User APIs
A guide on how to use miniOrange User APIs to create/update/get users.

Overview

miniOrange User APIs can be used to create/update/get users.

Pre-requisites

1. Create User API

To create a user, you need to make a HTTP POST request to our create user API. Our Create User API accepts the JSON input.


Request

Method URL
POST https://auth.miniorange.com/moas/api/admin/users/create

Request Headers:
Type Params Values
HEAD Content-Type application/json
HEAD Customer-Key int
HEAD Timestamp int
HEAD Authorization String

Customer­Key
Customer­Key​ is customer key for your account and must be sent with all client requests.

Timestamp
Timestamp​ specifies current time in milliseconds e.g 1474522813982.

Authorization
Authorization​ specifies SHA 512 hash value of string concatenated with customerKey, time in  milliseconds and  api key for your account e.g  sha512(customerKey + timeInMillis + apiKey).


Sample Code for Request Headers:
JavaPhp
/* The customer Key provided to you */ String customerKey = "<YOUR_CUSTOMER_KEY>"; /* The customer API Key provided to you */ String apiKey = "<YOUR_API_KEY>"; /* Current time in milliseconds since midnight, January 1, 1970 UTC. */ String currentTimeInMillis = String.valueOf(System.currentTimeMillis()); /* Creating the Hash using SHA-512 algorithm (Apache Shiro library) */ String stringToHash = customerKey + currentTimeInMillis + apiKey; String hashValue = new Sha512Hash(stringToHash).toHex().toLowerCase(); HttpPost postRequest = new HttpPost("<URL for calling API>"); /* Setting the Authorization Header values */ postRequest.setHeader("Customer-Key", customerKey); postRequest.setHeader("Timestamp", currentTimeInMillis); postRequest.setHeader("Authorization", hashValue) /* The customer Key provided to you */ $customerKey = "<YOUR_CUSTOMER_KEY>"; /* The customer API Key provided to you */ $apiKey = "<YOUR_API_KEY>"; /* Current time in milliseconds since midnight, January 1, 1970 UTC. */ $currentTimeInMillis = round(microtime(true) * 1000); /* Creating the Hash using SHA-512 algorithm */ $stringToHash = $customerKey . number_format ( $currentTimeInMillis, 0, '', '' ) . $apiKey; $hashValue = hash("sha512", $stringToHash); $customerKeyHeader = "Customer-Key: " . $customerKey; $timestampHeader = "Timestamp: " . number_format ( $currentTimeInMillis, 0, '', '' ); $authorizationHeader = "Authorization: " . $hashValue; /* Add $customerKeyHeader,$timestampHeader and $authorizationHeader in the httpheader */

Request Parameters:
Params Type
customerKey (required) int
username (required) String
email (required) String
firstName (required) String
lastName (required) String
phone (optional) String
password (optional) String
sendEmail (optional) Boolean
groups (optional) ArrayList
alternateEmail (optional) String
customAttribute1 (optional) String
customAttribute2 (optional) ... String
customAttribute50 (optional) String

Example Request Body

{ "customerKey" : 116, "username" : "xyz123", "email" : "xyz@example.com", "firstName" : "john", "lastName" : "doe" }

Example Response

{ "userId" : 12345, "username" : "xyz123", "email" : "xyz@example.com", "status" : "SUCCESS", "message" : "End user created successfully." }

Example Java code for Request Body with Group Object

JSONArray groupjsonarray = new JSONArray(); String[] arr = {"test_group1","test_group2"}; for(int i=0;i < arr.length;i++){ JSONObject groupjson = new JSONObject(); groupjson.put("name",arr[i]); groupjsonarray.add(groupjson); } Map<String,Object> map = new HashMap<String,Object>(); map.put("customerKey",customerKey); map.put("username", "apitestuser"); map.put("email", "xyz123@example.com"); map.put("firstName","john"); map.put("lastName","doe"); map.put("groups",groupjsonarray); JSONObject json = new JSONObject(); json.putAll( map ); String jsonString = json.toJSONString(); /* request json */ { "customerKey" : 116, "username" : "xyz123", "email" : "xyz@example.com", "firstName" : "john", "lastName" : "doe", "groups":[{"name":"test_group1"},{"name":"test_group2"}]} }

2. Update User API

To update an existing user, you need to make a HTTP POST request to our update user API. Our Update User API accepts the JSON input.


Request

Method URL
POST https://auth.miniorange.com/moas/api/admin/users/update
Request Headers:

Same as above


Request Parameters:
Params Type
customerKey (required) int
username (required, can't be updated) String
email (required) String
firstName (optional) String
lastName (optional) String
phone (optional) String
alternateEmail (optional) String
customAttribute1 (optional) String
customAttribute2 (optional) ... String
customAttribute50 (optional) String

Example Request Body

{ "customerKey" : 116, "username" : "xyz123", "email" : "abc@example.com", "firstName" : "john", "lastName" : "doe", "phone" : "+18888888888", "alternateEmail" : "abc@gmail.com" }

Example Response

{ "userId" : 12345, "username" : "xyz123", "email" : "xyz@example.com", "status" : "SUCCESS", "message" : "End User details are updated successfully." }

3. Get All Users API

To get all users, you need to make a HTTP POST request to our get user API. Our Get User API accepts the JSON input. Maximum 500 users allowed to fetch in single batch. 


Request

Method URL
POST https://auth.miniorange.com/moas/api/admin/users/getall
Request Headers:

Same as above


Request Parameters:
Params Type
customerKey (required) int
batchSize (required) int
batchNo (required) int

Example Request Body

{ "customerKey" : 116, "batchSize" : 500, "batchNo" : 1 }

Example Response

{  "customerId":116,      "status":"SUCCESS",      "message":"End Users retrieved successfully.",      "users":[           {              "userId":123,            "customerId":116,            "fname":"first name",            "lname":"last name",            "primaryEmail":"​testuser@miniorange.com​",            "primaryPhone":"+1",                       "creationDttm":1474309008638,            "lastUpdatedDttm":1474309008677,            "username":"test1", "alternateEmail":"testuser@gmail.com", "secondFactorAuthType":"sms", "customAttribute1":"", "customAttribute2":"", . . . . .              . . . . .  "customAttribute50":""        }      ],      "fetchedCount":1,      "nextBatch":2  }

4. Get User API

To search and get a single user, you need to make a HTTP POST request to our get user API. Our Get User API accepts the JSON input.


Request

Method URL
POST https://auth.miniorange.com/moas/api/admin/users/get
Request Headers:

Same as above


Request Parameters:
Params Type
customerKey (required) int
Username (required) String

Example Request Body

{ "customerKey" : 116, "username" : 'abc5' }

Example Response

{  "userId":123,      "status":"SUCCESS",      "message":"End User retrieved successfully.",      "username":"test1", "email":"xyz@example.com", "authType":"SMS", "users":[           {              "userId":123,            "customerId":116,            "fname":"first name",            "lname":"last name",            "primaryEmail":"​testuser@miniorange.com​",            "primaryPhone":"+1",                       "creationDttm":1474309008638,            "lastUpdatedDttm":1474309008677,            "username":"test1", "alternateEmail":"testuser@gmail.com", "secondFactorAuthType":"sms", "customAttribute1":"", "customAttribute2":"", . . . . .              . . . . .  "customAttribute50":""        }      ]     }
/* If user not found */ { "username":"abctest0", "status":"FAILED", "message":"Invalid username or email." }


5. Delete User API

To delete a single user, you need to make a HTTP POST request to our delete user API. Our Delete User API accepts the JSON input.


Request

Method URL
POST https://auth.miniorange.com/moas/api/admin/users/delete
Request Headers:

Same as above


Request Parameters:
Params Type
customerKey (required) int
Username (required) String

Example Request Body

{ "customerKey" : 116, "username" : 'abc5' }

Example Response

{  "customerId":123,      "status":"SUCCESS",      "message":"End User deleted successfully.",      }
/* If user not found or request json is incorrect*/ { You are not authorized to perform this operation }