Skip to content

Commit fd3a98d

Browse files
authored
chore: copy & paste friendly curl API example (#1305)
<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> ```
1 parent 390eb12 commit fd3a98d

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/api/index.tsx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,13 @@ export default function Api() {
137137
>
138138
<ClientCodeWrapper>
139139
<CodeBlock title="cURL" language='bash'>
140-
{`# Prepare Actor input
141-
cat > input.json <<'EOF'
142-
{
143-
// Define the input in JSON here
144-
}
145-
EOF
146-
147-
# Run the Actor
148-
curl "https://api.apify.com/v2/acts/username~actorname/runs?token=<YOUR_API_TOKEN>" \\
149-
-X POST \\
150-
-d @input.json \\
151-
-H 'Content-Type: application/json'
152-
153-
# Use the defaultDatasetId from response and pass it instead of <DATASET_ID>
154-
curl "https://api.apify.com/v2/datasets/<DATASET_ID>/items?token=<YOUR_API_TOKEN>"`
155-
}
140+
{`# Prepare Actor input and run it synchronously
141+
echo '{ "searchStringsArray": ["Apify"] }' |
142+
curl -X POST -d @- \\
143+
-H 'Content-Type: application/json' \\
144+
-H 'Authorization: Bearer <YOUR_API_TOKEN>' \\
145+
-L 'https://api.apify.com/v2/acts/compass~crawler-google-places/run-sync-get-dataset-items'
146+
`}
156147
</CodeBlock>
157148
</ClientCodeWrapper>
158149
</SectionWrapper>

0 commit comments

Comments
 (0)