Return data to API call

Hello, I'm trying to return the data from an Apify actor via the same REST API call that initiated the actor. Is this possible? This page says I need to put the value in OUTPUT in the "default key-value store": https://docs.apify.com/platform/tutorials/run-actor-and-retrieve-data-via-api#synchronous-runs-with-dataset-output But the "put record" documentation seems to require a key value store ID. Is there a default here? https://docs.apify.com/api/v2#/reference/key-value-stores/record/put-record So I'm trying to figure out how to return data. From within the Actor, am I supposed to call the key-value store API, put a new record, with the recordKey of OUTPUT, and JSON data of the value? If so, what should storeId be? Is there an easier way to do this? I wish I could just type return and return the value ...
Run actor and retrieve data via API | Apify Documentation
Learn how to run an actor/task via the Apify API, wait for the job to finish, and retrieve its output data. Your key to integrating actors with your projects.
No description
3 Replies
xenophobic-harlequin
xenophobic-harlequin3y ago
There are several ways. One is to save the output to OUTPUT in key-value store. Pretty much what you described above. Another options is to use the following endpoint - https://docs.apify.com/api/v2#/reference/actors/run-actor-synchronously-and-get-dataset-items/run-actor-synchronously-with-input-and-get-dataset-items if you don't mind having several calls - you could use the last run endpoint: https://docs.apify.com/api/v2#/reference/actors/last-run-object-and-its-storages/run-actor-synchronously-with-input-and-get-dataset-items Of of course it's possible to run the actor, wait for finish, fetch IDs, fetch dataset, etc, but from your description you want to have 1 call - so it's either OUTPUT, or start run and get dataset items.
robust-apricot
robust-apricotOP3y ago
Oh awesome - I didn't know about the run-actor-synchronously and get dataset option. I'll give that a try Thank you!
xenophobic-harlequin
xenophobic-harlequin3y ago
Sure thing and happy to help! Ping us if something isn't clear 👍

Did you find this page helpful?