Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: copy & paste friendly curl API example #1305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

netmilk
Copy link
Contributor

@netmilk netmilk commented Nov 27, 2024

image
  • 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>

@jancurn
Copy link
Member

jancurn commented Nov 27, 2024

Thanks for looking into it.

  • Please can we make the code not depending on manually-entered <DATASET_ID> ? Basically so that you can run it and and see results right away
  • I'd consider using an Actor that is not PPR, e.g. Website Content Crawler

@netmilk
Copy link
Contributor Author

netmilk commented Nov 27, 2024

Please can we make the code not depending on manually-entered <DATASET_ID> ? Basically so that you can run it and and see results right away

Sure, we can do that, but I would consider the learning and communication value of the code example on the Docs API landing page. I thought about having the API key exported at the very top and the dataset ID extracted with jq into another constant, but it seemed harder to read compared to having the reader manually replace the placeholders and understand what they’re doing.

If we want a super simple one-liner curl example to demo Apify (API), I'd consider adding a convenience API endpoint that:

  • calls the actor
  • waits for its start
  • it streams the default dataset content.

(if that's even possible)

@jancurn
Copy link
Member

jancurn commented Nov 27, 2024

Yeah, cool, we have an API endpoint for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants