Create Mobileuser

From MyMobileWorkers API
Jump to: navigation, search

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

The JSON file is passed in the post as the "file"
Standard Fields
Field Expected Data Required
username varchar(32) ✓
external_id varchar(45)
email varchar(127)
fullname varchar(32)
password varchar(45) ✓
branch_id {"name":"<branchName>"}
*nested JSON object
engineer_reg_number varchar(45)
contact_number varchar(45)
Fields exclusive to JSON body format:
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"
    }
  ]
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox