Adding & Updating Users via the Web API



This article shows how to programatically create and update local InstantKB user accounts remotely via the InstantKB Web API. To learn how to authenticate your requests please see "How Web API Authentication Works".

Creating InstantKB Users via the Web API

The request below shows the minimum data you can provide to create a local user account within your InstantKB database via the InstantKB Web API...

POST api/user HTTP/1.1
Host: https://demos.instantasp.co.uk/InstantKB2018/
Authorization: Basic {your_application_key}
Content-Type: application/json
X-Api-Version: 1


data: "{\n\tusername: \"new user\",\nemail_address: \"new@user.com\",\npassword: \"Ds83$n£8C#212\"\n}"

This request will fail if you don't provide a valid Application Key.

IMPORTANT
As user credentials are being passed over the wire with this request we would strongly recommend using a secure connection when posting data to the "api/user" endpoint.

Updating InstantKB user accounts via the Web API

When updating existing user accounts via the InstantKB Web API only the user account matching the supplied user key within the authorization header would be updated. For example to update the username for a user within InstantKB you can make the following request ensuring the supply the user key for the account you wish to update as shown below...

PUT api/user HTTP/1.1
Host: https://demos.instantasp.co.uk/InstantKB2018/
Authorization: Basic {app_key}:{user_key}
Content-Type: application/json
X-Api-Version: 1


data: "{\nusername: \"my new username\"\t\n}"

If you supply a valid support agent or administrator user key within the authorization header for your request you can also specify an additional "id" parameter within your request to update any existing user account, not just the account matching the supplied user key. You can see this below we are updating the username for the user account with id 1025...

PUT api/user HTTP/1.1
Host: https://demos.instantasp.co.uk/InstantKB2018/
Authorization: Basic {app_key}:{admin_user_key}
Content-Type: application/json
X-Api-Version: 1


data: "{\nid: 1025,\nusername: \"my new username\"\t\n}"

If you don't supply a valid support agent or administrator user key within the authorization header and attempt to update another users account the request will fail.