Difference between revisions of "Create Mobileuser"
(→JSON As Body) |
|||
| Line 1: | Line 1: | ||
== Summary == | == Summary == | ||
| + | A mobile user can be created via two different methods - either as multi-part form data with a JSON file attached and the API key as a parameter, or as JSON content on it's own, with the API key supplied within the JSON. | ||
| + | |||
| + | The 'create mobile user' method accepts an array of mobile users to be added to the system. If the 'update_existing' parameter is set, then any existing items will be updated in the system. If set to false or not provided, then any item where the username is not unique will be rejected. | ||
If 'validate_only' is set, the assets will only be validated but not actually inserted into the database. This can be used to check an entire dataset for errors before submitting. | If 'validate_only' is set, the assets will only be validated but not actually inserted into the database. This can be used to check an entire dataset for errors before submitting. | ||
| + | ''' The password is encrypted once received by the API, as a result it will be impossible to ever recover/receive the password back in a response. If the user is updated and you do not wish to update the password pass a null value ''' | ||
==== Multi Part Form Data ==== | ==== Multi Part Form Data ==== | ||
| Line 107: | Line 111: | ||
==== Multi Part Form Data ==== | ==== Multi Part Form Data ==== | ||
| + | <source lang="java"> | ||
| + | { "mobile_users":[ | ||
| + | { | ||
| + | "username":"MrUser", | ||
| + | "branch_id":{ | ||
| + | "name":"Hub" | ||
| + | }, | ||
| + | "engineer_registration_number":"ABC", | ||
| + | "fullname":"Bob User", | ||
| + | "contact_number":"0192576845", | ||
| + | "email":"MrUser@mymobileworkers.com", | ||
| + | "password":"VerySecure" | ||
| + | |||
| + | } | ||
| + | ]} | ||
| + | </source> | ||
==== JSON As Body ==== | ==== JSON As Body ==== | ||
| + | <source lang="java"> | ||
| + | { | ||
| + | "key":"myApiKey", | ||
| + | "update_existing":true, | ||
| + | "mobile_users":[ | ||
| + | { | ||
| + | "username":"MrUser", | ||
| + | "branch_id":{ | ||
| + | "name":"Hub" | ||
| + | }, | ||
| + | "engineer_registration_number":"ABC", | ||
| + | "fullname":"Bob User", | ||
| + | "contact_number":"0192576845", | ||
| + | "email":"MrUser@mymobileworkers.com", | ||
| + | "password":"VerySecure" | ||
| − | + | } | |
| + | ]} | ||
| + | </source> | ||
| + | == Example Curl Requests == | ||
| + | |||
==== Multi Part Form Data ==== | ==== Multi Part Form Data ==== | ||
| − | curl -F validate_only=false -F update_existing=true -F api_key= | + | curl -F validate_only=false -F update_existing=true -F api_key=APIKEY -F file=@/Users/user/Desktop/webAPICurling/create_mobile_users.txt https://api.mymobileworkers.com:8181/api/1/mobile_users |
==== JSON As Body ==== | ==== JSON As Body ==== | ||
| − | curl -X POST -H "Content-Type: application/json" -d '{"key":" | + | curl -X POST -H "Content-Type: application/json" -d '{"key":"myApiKey","update_existing":true,"mobile_users":[{"username":"MrUser","branch_id":{"name":"Hub"},"engineer_registration_number":"ABC","fullname":"Bob User","contact_number":"0192576845","email":"MrUser@mymobileworkers.com","password":"VerySecure"}]}' https://api.mymobileworkers.com:8181/api/1/mobile_users |
== Responses == | == Responses == | ||
=== Example JSON === | === Example JSON === | ||
| + | <source lang="java"> | ||
| + | { | ||
| + | "failed": [ | ||
| + | { | ||
| + | "name": "MrBadUser", | ||
| + | "errors": [ | ||
| + | { | ||
| + | "error_code": "MBU004", | ||
| + | "error_message": "No Password provided" | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | ], | ||
| + | "successful": [ | ||
| + | { | ||
| + | "name": "MrUser" | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | </source> | ||
Revision as of 21:51, 18 May 2017
Contents |
Summary
A mobile user can be created via two different methods - either as multi-part form data with a JSON file attached and the API key as a parameter, or as JSON content on it's own, with the API key supplied within the JSON.
The 'create mobile user' method accepts an array of mobile users to be added to the system. If the 'update_existing' parameter is set, then any existing items will be updated in the system. If set to false or not provided, then any item where the username is not unique will be rejected.
If 'validate_only' is set, the assets will only be validated but not actually inserted into the database. This can be used to check an entire dataset for errors before submitting.
The password is encrypted once received by the API, as a result it will be impossible to ever recover/receive the password back in a response. If the user is updated and you do not wish to update the password pass a null value
Multi Part Form Data
| Create Asset | ||
|---|---|---|
| URL | https://base_url/api_path/version/mobile_users | |
| Type | POST | |
| Params: | api_key | required |
| file | required | |
| update_existing | optional (default = false) | |
| validate_only | optional (default = false) | |
| Response | JSON | |
JSON As Body
| Create Job - JSON | ||
|---|---|---|
| URL | https://base_url/api_path/version/mobile_users | |
| Type | POST | |
| JSON {key, validate_only(optional), update_existing(optional), mobile_users[]} |
required | |
| Response | JSON | |
JSON Contents
| Standard Fields | ||
|---|---|---|
| Field | Expected Data | Required |
| username | varchar(32) | ✓ |
| varchar(127) | ||
| fullname | varchar(32) | |
| password | varchar(45) | ✓ |
| branch_id | {"name":"<branchName>"} *nested JSON object |
|
| engineer_reg_number | varchar(45) | |
| contact_number | varchar(45) | |
| Standard Fields | ||
|---|---|---|
| Field | Expected Data | Required |
| key | string - company api key | ✓ |
| update_existing | boolean | |
| validate_only | boolean | |
Example Input
Multi Part Form Data
{ "mobile_users":[ { "username":"MrUser", "branch_id":{ "name":"Hub" }, "engineer_registration_number":"ABC", "fullname":"Bob User", "contact_number":"0192576845", "email":"MrUser@mymobileworkers.com", "password":"VerySecure" } ]}
JSON As Body
{ "key":"myApiKey", "update_existing":true, "mobile_users":[ { "username":"MrUser", "branch_id":{ "name":"Hub" }, "engineer_registration_number":"ABC", "fullname":"Bob User", "contact_number":"0192576845", "email":"MrUser@mymobileworkers.com", "password":"VerySecure" } ]}
Example Curl Requests
Multi Part Form Data
curl -F validate_only=false -F update_existing=true -F api_key=APIKEY -F file=@/Users/user/Desktop/webAPICurling/create_mobile_users.txt https://api.mymobileworkers.com:8181/api/1/mobile_users
JSON As Body
curl -X POST -H "Content-Type: application/json" -d '{"key":"myApiKey","update_existing":true,"mobile_users":[{"username":"MrUser","branch_id":{"name":"Hub"},"engineer_registration_number":"ABC","fullname":"Bob User","contact_number":"0192576845","email":"MrUser@mymobileworkers.com","password":"VerySecure"}]}' https://api.mymobileworkers.com:8181/api/1/mobile_users
Responses
Example JSON
{ "failed": [ { "name": "MrBadUser", "errors": [ { "error_code": "MBU004", "error_message": "No Password provided" } ] } ], "successful": [ { "name": "MrUser" } ] }