[Bug] JS Apify Client not updating tasks correctly
I am using the Apify JS client to update a task's inputs and options and am finding that it is not correctly honoring the API documentation
https://docs.apify.com/api/v2#/reference/actor-tasks/task-collection/update-task
In this doc, it says "If the object does not define a specific property, its value is not updated." However, in my testing, I have found that this is not the case. Rather, it will fail if any required variables are missing from the update patch. Even worse, options that aren't specified are removed entirely.
Take this example with the website content crawler actor. I can get the task information by its ID, but when I try to update just the
"crawlerType"
, I get an error that "startUrls"
is missing even though it clearly already exists on the task. Even more interestingly, the operation succeeds when I use the updateInput
endpoint. Why is the behavior correctly following the documentation for updateInput
but not update
?
https://gist.github.com/omikader/efe8c75eff27c36a4edeb782ddf59006Gist
Apify update task errors
Apify update task errors. GitHub Gist: instantly share code, notes, and snippets.
3 Replies
rival-black•13mo ago
Hi,
update
and updateInput
operate on different objects:
- update
updates task object (properties input
, name
, actId
etc)
- updateInput
updates input object (properties startUrls
, maxResults
etc)
If you call await client.task("abc123").update({ input: { "crawlerType": "playwright:firefox" } })
, it will replace task's input
property (whole object) with { input: { "crawlerType": "playwright:firefox" }
and won't update other properties.
So to update only a part of the task's input, you need to use updateInput
.conscious-sapphireOP•13mo ago
Thanks for clarifying @ondro_k! I think the documentation should be updated accordingly to reflect this as the current information is not accurate
If the object does not define a specific property, its value is not updated.
rival-black•13mo ago
Thanks for the feedback. I'll let our docs guys know to make the descriptions clearer.