Creating A New User With The API

The API uses JavaScript Object Notation (JSON) to enable other applications to connect to Prodeceo.

Before you can begin, you need to obtain an API key. If you do not yet have a key, please see the related articles listed below.

To create a user we describe the user in JSON format. You may include all fields that you would fill in when creating a user manually.

An example might be:

{
  "title" : "Mr",
  "first_name" : "John",
  "last_name" : "Smith",
  "email" : "john.smith@prodeceo.com",
  "password" : "s3cret_passW0rd",
  "role" : "Trainee"
}

If you wish to add the user to groups, then you can include a nested object under the key "groups". Groups are identified by a category and a name, so the groups must be placed under the key of the category that they represent. The value for each category should be an array of group names.

{
  "position" : ["Account Manager"]
  "location" : ["Worcester"]
}

If a group does not exist in the assigned category it will automatically be created.

A full example might look like

{
  "title" : "Mr",
  "first_name" : "John",
  "last_name" : "Smith",
  "email" : "john.smith@prodeceo.com",
  "password" : "s3cret_passW0rd",
  "role" : "Trainee",
  "groups" : {
    "position" : ["Account Manager"],
    "location" : ["Worcester"]
  }
}

When the JSON describing the user has been defined it needs to be submitted to the server via a POST request. The URL for the request should be https://xyz.prodeceo.com/api/v1/users.json replacing 'xyz' with the name of your account.

In addition to the user, you must also submit your api_key with each request so that your request can be authenticated correctly.

A complete example of creating a user via the API using ruby is shown below.


require 'net/http'
require 'json'

## Complete these details
account_name = "xyz"
api_key = "abc"
##

host = "#{account_name}.prodeceo.com"
port = '443'

url = "/api/v1/users"

payload ={
	:api_key => "#{api_key}",
  :user => {
  "title" => "Mr",
    "first_name" => "John",
    "last_name" => "Smith",
    "email" => "john.smith@prodeceo.com", 
    "password" => "s3cret_passW0rd",
    "groups" => {"position" => ["Account Manager"], "location" => ["Worcester"]},
    "role" => "Trainee"
	}
}.to_json

req = Net::HTTP::Post.new(url, initheader = {'Content-Type' =>'application/json'})
req.body = payload

response = Net::HTTP.new(host, port).start {|http| http.request(req) }

puts "Response #{response.code} #{response.message}:\n#{response.body}"

We have conducted numerous integrations on behalf of our clients and can help with your integration if required.

If you need futher assistance please contact us.

See Also

Generating an API Key , Adding A Trainee

Categories

API

Author: Adam Chester (last updated 28/07/2014)