Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Endpoints >

Post time to project via API

Started by Lydia Castano -   in API Endpoints


I'm using postman for testing my API calls. I'm using projects end point to add time to an existing project (https://developer.xero.com/documentation/projects/time). I can search and get the project, search for tasks or users so I have all the IDs to use in my call.
When using put to update an existing time entry, I don't have any issue. But when I use post to create a new time entry to the project I'm getting the error message "The resource you're looking for cannot be found" (404 Not found). I don't know why I'm getting that error when the update time is working fine. Any idea?


Parametes I'm using in postman:
POST https://api.xero.com/projects.xro/2.0/projects/01234567-89ab-cdef-0123-456789abcdef/time
Authorization OAuth 1.0
Headers "key":"Accept","value":"application/json", "key":"Content-Type","value":"application/json"
Body raw -> JSON (application/json)
"userId": "8e55a91c-ad9f-4b82-8981-1917d4a545e5",
"taskId": "f4ca82a5-72a5-496b-855a-c9aaab1a991c",
"dateUtc": "2015-01-01T23:34:15Z",
"duration": 120,
"description": "Test postman"
Xero's accounting API was originally implemented with the PUT and POST verbs reversed.
PUT is for "create" and POST is for "update". This is non-standard behavior, but I believe we've keep it consistent across all APIs. If you PUT with an ID, you'll get an update, while performing a PUT without a unique id will result in a create. Give it a shot in Postman and let us know if that doesn't work.

Sidney Maestre (Community Manager)  

Unfortunately I get the same error message and the time entry is not created.
I tested again the update with PUT and everything was correct and I can see the changes in Xero. I duplicated that call, deleted the time ID from the URL, send the call and I got "404 Not found" "The requested resource could not be found".

So, with the same json body:

PUT https://api.xero.com/projects.xro/2.0/projects/c22b58a5-6af0-4992-8e1b-2c84c57ab2b5/time/9a36e45c-d67d-4c69-acb8-d5897b58085e works

PUT https://api.xero.com/projects.xro/2.0/projects/c22b58a5-6af0-4992-8e1b-2c84c57ab2b5/time doesn't work

Lydia Castano  

I'm getting the same result as Lydia above.

I can update existing time entries, but I can't create new entries using PUT or POST

Jarvis Mishler  

I have my issue fixed now. For the calls that failed, I was using the userid I got from https://api.xero.com/api.xro/2.0/users. I changed the userid to the ones I got from https://api.xero.com/projects.xro/2.0/projectsusers and the POST call to insert times worked.

Lydia Castano  

I'm in a similar situation. I've tried posting to create both projects and time. And each time I get the following error with a 400 response:

'message': 'The request is invalid.',
'modelState': 'model': 'An error has occurred.'

When I use put, I get a 404 response with no message.

Reuben Cummings  

For me, change the userid on the POST call to use the one from https://api.xero.com/projects.xro/2.0/projectsusers fixed the issue.

Lydia Castano