Skip to content

Commit

Permalink
chore: copy & paste friendly curl API example (#1305)
Browse files Browse the repository at this point in the history
<img width="623" alt="image"
src="https://github.com/user-attachments/assets/f839e94b-a9e8-45ce-a03e-12cf962367b8">

- the commands are restructured in a way that the editable part is
always at the end of the snippet (especially annoying in multi-line
snippets)
- added the saving of the response of the Run to a `run.json `
- added convenience `jq` command to find the dataset in the Actor run
response
- removed (imo) unnecessary quotes
- squished the per command line breaks to save lines

Please, try it yourself before merging:

```
# Prepare Actor input
echo '{ "searchStringsArray": ["Apify"] }' > input.json

# Run the Actor and retreive its default dataset id.
curl -X POST -d @input.json -H 'Content-Type: application/json' \
  -s -o >(tee run.json) \
  https://api.apify.com/v2/acts/compass~crawler-google-places/runs?token=<YOUR_API_TOKEN>

# Find the defaultDatasetId in the API response 
cat run.json | jq -r .data.defaultDatasetId

# And pass it instead of <DATASET_ID>
curl https://api.apify.com/v2/datasets/<DATASET>/items?token=<YOUR_API_TOKEN>
```
  • Loading branch information
netmilk authored Jan 20, 2025
1 parent 390eb12 commit fd3a98d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 7 additions & 16 deletions src/pages/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,13 @@ export default function Api() {
>
<ClientCodeWrapper>
<CodeBlock title="cURL" language='bash'>
{`# Prepare Actor input
cat > input.json <<'EOF'
{
// Define the input in JSON here
}
EOF
# Run the Actor
curl "https://api.apify.com/v2/acts/username~actorname/runs?token=<YOUR_API_TOKEN>" \\
-X POST \\
-d @input.json \\
-H 'Content-Type: application/json'
# Use the defaultDatasetId from response and pass it instead of <DATASET_ID>
curl "https://api.apify.com/v2/datasets/<DATASET_ID>/items?token=<YOUR_API_TOKEN>"`
}
{`# Prepare Actor input and run it synchronously
echo '{ "searchStringsArray": ["Apify"] }' |
curl -X POST -d @- \\
-H 'Content-Type: application/json' \\
-H 'Authorization: Bearer <YOUR_API_TOKEN>' \\
-L 'https://api.apify.com/v2/acts/compass~crawler-google-places/run-sync-get-dataset-items'
`}
</CodeBlock>
</ClientCodeWrapper>
</SectionWrapper>
Expand Down

0 comments on commit fd3a98d

Please sign in to comment.