Post

1 follower Follow
0
Avatar

changeState API endpoint - sending multiple Ids

Hi,

I'm trying to send multiple Timesheet IDs to the "data/changeState" endpoint but I keep getting back internal error references.

A single reference works using the following POST data:

'{"Ids":["\\/Timesheet\\/3fqab93oa3fjzdgvb65rwx634747"],"state":"UnSubmitted"}',

Multiple like this however fails:

'{"Ids":[["\\/Timesheet\\/469cigpcql4epl9wpwb2vf4t837"],["\\/Timesheet\\/6hh3kuofvxlh46kbht7lvcrxg459"]],"state":"Submitted"}',

Example references: 3lI3Cqa1zoDydJDS2JjmjO

Is it possible to send multiple Ids in one call? Or would I need to make multiple calls, specifying one Timesheet Id per call?

Jamie Lowe Answered

Please sign in to leave a comment.

1 comment

1
Avatar

I have now resolved this issue using the bulk/execute endpoint as follows with the following request in case anybody else stumbles across the same issue as it took me a few hours to figure this out...

foreach($data as $ts) {
$id = $ts['external_id'] //The External Reference from Clarizen TS
$params['requests'][] = [
'url' => "/data/changeState",
'method' => 'POST',
'body' => [
'Ids' => ["/Timesheet/{$id}"],
'state' => '{YOUR_REQUIRED_STATE}'
],
];
}
$this->clarizen = $this->curl_request('/bulk/execute', $params, 'post', $session, $server_details['serverLocation']);
$this->clarizen = json_decode($this->clarizen, true);
foreach($this->clarizen['responses'] as $message) {
if($message['statusCode'] != 200) {
$errors[] = $message['body']['message'];
}
}

if(!empty($errors)) {
var_dump($errors); //There will be multiple requests with potentially different errors, log them all.
exit(1);
}
Jamie Lowe 1 vote