User Creation - Documentation


#1

Hey all, I have been trying to create a user via the api on sandbox with no luck. Im sending a post request to “https://api.sandbox.freeagent.com/v2/users” which is telling me that Im missing the parameter “user”, I have looked in the documentation and can’t find any mention of it, I have tried all sorts to try to get it to work to no avail. Would someone be able to post a snippet or tell me what data I need to pass into the user parameter (In the documentation there is mention to a root user element but I do not know what this is specifically referring to).

Here is few things I have tried for the user:

  • The url for root user (User logged in as)

  • The required parameters that are required by the documentation

  • The root users id from url.

Here is a snippet of the body structures Im sending in my post:

    let user = {
        'user': rootUrl,
        'email': email,
        'first_name': firstName,
        'last_name': lastName,
        'opening_mileage': mileage,
        'role': 'Employee',
        'permission_level': 0,
        'send_invitation': false
    }

Thanks :smile:


#2

Hi Paul,

Sorry to hear you’re having difficulty. When you are attempting to create a user, you’re probably looking at our create user docs. You can see a note in here that

Payload should have a root user element, containing elements listed under Attributes.

What does this mean? The XML and JSON samples for the response do contain clues, but they can be easy to miss. If you look at this JSON response from the docs:

{ "user":
  {
    "first_name":"Development",
    "last_name": "Team",
     ...
   }
}

You’ll see that there is an outer “user” element, which is a key in the associative array. The matching value is another associative array, that contains the parameters for the user object. You should be using this style of structure to create any new object against the API.

I hope that helps,

James


#3

Hey James, thanks for the help however Im still struggling to get it to work here is what Im sending now:

	let user = {
		"user": {
			"email": email,
			"first_name": firstName,
			"last_name": lastName,
			"opening_mileage": mileage,
			"role":  "Employee",
			"permission_level": 0,
			"send_invitation": false
		}
	}

But it keep sending back “Not Found”.

Thanks,
Paul


#4

Anyone able to help as I need to integrate this into our app?

Thanks,
Paul


#5

Hi @Paul92,

Sorry to hear you’re still having difficulty getting this working. I think the best way to diagnose this now is for you to retry the request, and then to message me your API application ID. If you could also send the approximate time that you made your request, we can dig through the logs on our sandbox environment and see if we can track down the issue.

To send the message to me directly, click on my avatar and then select “Message”.

Best regards,
James