401 unauthorised response when creating new user


#1

Hi there,

Just started playing around with the Sandbox API using the Google OAuth 2.0 Playground as directed by the start up instructions. I’m trying to create a new user as per the instructions on the API docs User page.

When sending the below POST request to https://api.sandbox.freeagent.com/v2/users

{
“user”: [
{
“first_name”: “Steve”,
“last_name”: “Bruce”,
“role”: “Employee”,
“opening_mileage”: “0.0”,
“email”: "steve.bruce@path.co.uk"
}
]
}

I get a “401 Unauthorized” response and not sure why.

The GET request (without payload) works absolutely fine and the active user has full authorization (Level 8) so just can’t figure it out…

Am I missing something?
Hopefully not a stupid question!
Thanks in advance for your help.


#2

You are sending an array for the user; try taking out the square brackets so the user is a hash. E.g.

{
  "user": {
    "first_name": "Steve",
    ...
  }
}

#3

Thanks Andrew that worked!