I've found a few older Stackverflow-threads with the exact same question as this one but I can't get the solution to work.
Essentially, I'd like to add timeoffs and I've learnt that the only way to do so - according to [1] - is by making a PUT request, add existing objects into the collection and add new objects without the ID.
I've replicated the example as shown in [1]:
https://[DOMAIN].attasksandbox.com/attask/api/v5.0/RESVT?method=POST&sessionID=330051c6aaa24cb48edb3eab113d3a5a&updates=[{
"userID": "57270ab200030c6814a20577576f8399",
"startDate": "2016-08-12",
"endDate": "2016-08-15"
},
{
"ID": "575e7a27001a0dd8312a29defd886b78",
"objCode": "RESVT",
"startDate": "2016-06-01T00:00:00:000+0200",
"endDate": "2016-06-04T00:00:00:000+0200",
"userID": "57270ab200030c6814a20577576f8399"
}]&atomic=true
Response when executing the request:
{
"data": [
{
"objCode": "RESVT",
"ID": "575e7410001a031e06534a49b3032fd1"
},
{
"objCode": "RESVT",
"ID": "575e7410001a031f1ee4a0379c96d287"
}
]
}
But the only timeoff I see in the user's Timeoff page (and when searching for timeoff objects via the API) is the last object in the updates-parameter. In the example above it would be June 1-4. If I re-arrange the updates-array so June 1-4 is the first in the list then I see August 12-15 instead.
I've also tried using method=PUT instead of method=POST but then I get this message:
{
"error": {
"class": "java.lang.IllegalArgumentException",
"message": "Must specify an ID for each object that is edited"
}
}
What am I doing wrong?
[1]: php - AtTask API - Adding Time Off Hours - Stack Overflow AtTask API - Adding Time Off Hours
The issue you are having is you are making the update at the RESVT object and not the USER object so each call is adding a new item to the users timeOff replacing all previous entry so the reason you are only seeing the Last on is because it was the last one to run and all previouse entries get erased.
To correct this you need to make the Update at the user object and update the Reserved Time Collection.
You can do this with the following call.
PUT /attask/api/v4.0/user/[userID]?&sessionID=[sessionID]&updates=
{
reservedTimes:
[
{
"ID": "547debb6000dea62198bd66b7c73e174",
"objCode": "RESVT",
"endDate": "2014-07-08T23:59:00:163-0600",
"startDate": "2014-07-08T00:00:00:163-0600"
},
{
"ID": "547debb6000dea61b8c695ba24918fe8",
"objCode": "RESVT",
"endDate": "2014-02-13T23:59:00:329-0700",
"startDate": "2014-02-13T00:00:00:329-0700"
},
{
"objCode": "RESVT",
"endDate": "2014-02-14T23:59:00:329-0700",
"startDate": "2014-02-14T00:00:00:329-0700"
}
]
}