I’m trying to update tasks in bulk using Batch API
I’m passing JSON as the body in a php script like this:
function UpdateTasks() {
$aToken = '[REDACTED]';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://app.asana.com/api/1.0/batch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 90,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($GLOBALS['amz']),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $aToken
),
));
$response = curl_exec($curl);
$jArray = json_decode($response, true);
$err = curl_error($curl);
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($err) {
echo "\n cURL Error #:" . $err;
}
else
{
echo "Status Code: <br>" . $http_status . "<br> Response <br>" . $response;
}
}
However, Asana throws the below error:
Status Code:
400
Response
{"errors":[{"message":"Could not interpret {\"data\":{\"actions\":[{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/829561517314688\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - UK\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710721\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Canada\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710714\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - France\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710715\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Germany\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710716\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Italy\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710717\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Spain\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710719\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - USA\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710720\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - China\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710718\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Mexico\"}}]}} as an identifier in {\"data\":{\"actions\":[{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/829561517314688\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - UK\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710721\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Canada\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710714\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - France\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710715\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Germany\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710716\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Italy\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710717\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Spain\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710719\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - USA\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710720\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - China\"}},{\"method\":\"put\",\"relative_path\":\"\\/tasks\\/833683133710718\",\"data\":{\"completed\":\"false\",\"name\":\"[]unlinked on Trimming Shop - Mexico\"}}]}}.","help":"For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"}]}
Is this because I’m passing a encode_json value to the call and asana expects a json file?
Also, what exactly is the “Could not interpret” here referring to?
I’ve compared my JSON to the example mentioned at
and it looks correct.
I’m at my wits end. Any help is much appreciated.
Kind regards.