Add User
Purpose
To add a user to your organization.
Endpoints
Request Details
Request URL
{api-domain}/crm/{version}/users
Header
Authorization: Zoho-oauthtoken d92d4xxxxxxxxxxxxx15f52
Scope
scope=ZohoCRM.users.{operation_type}
Possible operation types
ALL - Full access to users
CREATE - To create users
You can add only one user per POST request.
Adding a CRM Plus user through API is not supported. You can only add a CRM Plus user through the UI.
You must use only Field API names in the input. You can obtain the field API names from Fields metadata API (the value for the key “api_name” for every field).
Sample Request
Copiedcurl "https://www.zohoapis.com/crm/v2.1/users"
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-d "@newuser.json"
-X POST
Copieduser1 = Map();
user1.put("last_name", "Shawn");
user1.put("email", "shawn@zylker.com");
user1.put("role", "692969000000015969");
user1.put("profile", "692969000000015972");
users = List();
users.add(user1);
params = Map();
params.put("users", users);
response = invokeurl
[
url: "https://www.zohoapis.com/crm/v2.1/users"
type: POST
parameters: params.toString()
connection:"crm_connection"
];
info response ;
Copied//Get instance of UsersOperations Class
$usersOperations = new UsersOperations();
//Get instance of BodyWrapper Class that will contain the request body
$request = new RequestWrapper();
//List of User instances
$userList = array();
$userClass = "com\zoho\crm\api\users\User";
//Get instance of User Class
$user1 = new $userClass();
$role = new Role();
$role->setId("34770610026008");
$user1->setRole($role);
$user1->setFirstName("TestUser");
$user1->setEmail("testuser@zoho.com");
$profile = new Profile();
$profile->setId("34770610026014");
$user1->setProfile($profile);
$user1->setLastName("12");
array_push($userList, $user1);
$request->setUsers($userList);
//Call createUser method that takes BodyWrapper class instance as parameter
$response = $usersOperations->createUser($request);
Copied<?php
class AddUser
{
public function execute(){
$curl_pointer = curl_init();
$curl_options = array();
$curl_options[CURLOPT_URL] = "https://www.zohoapis.com/crm/v2/users";
$curl_options[CURLOPT_RETURNTRANSFER] = true;
$curl_options[CURLOPT_HEADER] = 1;
$curl_options[CURLOPT_CUSTOMREQUEST] = "POST";
$requestBody = array();
$userArray = array();
$userObject = array();
$userObject["role"]="3524033000000026005";
$userObject["first_name"]="Variaggble33";
$userObject["email"] = "asda@asd.com";
$userObject["profile"] = "3524033000000026011";
$userObject["last_name"] = "sadasd";
$userArray[] = $userObject;
$requestBody["users"] =$userArray;
$curl_options[CURLOPT_POSTFIELDS]= json_encode($requestBody);
$headersArray = array();
$headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " . "1000.f62e4XXXXXXX02a293.0af14cXXXXX7beb";
$curl_options[CURLOPT_HTTPHEADER]=$headersArray;
curl_setopt_array($curl_pointer, $curl_options);
$result = curl_exec($curl_pointer);
$responseInfo = curl_getinfo($curl_pointer);
curl_close($curl_pointer);
list ($headers, $content) = explode("\r\n\r\n", $result, 2);
if(strpos($headers," 100 Continue")!==false){
list( $headers, $content) = explode( "\r\n\r\n", $content , 2);
}
$headerArray = (explode("\r\n", $headers, 50));
$headerMap = array();
foreach ($headerArray as $key) {
if (strpos($key, ":") != false) {
$firstHalf = substr($key, 0, strpos($key, ":"));
$secondHalf = substr($key, strpos($key, ":") + 1);
$headerMap[$firstHalf] = trim($secondHalf);
}
}
$jsonResponse = json_decode($content, true);
if ($jsonResponse == null && $responseInfo['http_code'] != 204) {
list ($headers, $content) = explode("\r\n\r\n", $content, 2);
$jsonResponse = json_decode($content, true);
}
var_dump($headerMap);
var_dump($jsonResponse);
var_dump($responseInfo['http_code']);
}
}
(new AddUser())->execute();
Copiedusers = []
# Get instance of Role Class
role = Roles::Role.new
# Set ID to Role instance
role.id = 3_524_033_000_000_026_011
# Set profile instance to profile in User instance
profile = Profiles::Profile.new
profile.id = 3_524_033_000_000_026_011
# Get instance of User Class
user = Users::User.new
# Get instance of Profile Class
user.profile = profile
# Set role instance to role in User
user.role = role
user.first_name = '1'
user.last_name = '1'
user.email = '1@zoho.com'
# Set the list to users in BodyWrapper instance
users.push(user)
# Get instance of RequestWrapper Class that will contain the request body
rw = Users::RequestWrapper.new
# List to hold User instances
rw.users = users
# Get instance of UsersOperations Class
uo = Users::UsersOperations.new
response = uo.create_user(rw)
Copiedrequire 'net/http'
require 'json'
class AddUser
def execute
url = URI( "https://www.zohoapis.com/crm/v2/users")
req = Net::HTTP::Post.new(url.request_uri)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
headers={}
headers["Authorization"]="Zoho-oauthtoken 1000.dfa7XXXXXXXXXXXXXXXXXX84f9665840.c176aeXXXXXXXXXXXX13f3d37a84d"
headers&.each { |key, value| req.add_field(key, value) }
request_body = {};
users_array = [];
user_object = {};
user_object["role"]="3524033000000026005";
user_object["first_name"]="Variaggble33";
user_object["email"] = "asda@asd.com";
user_object["profile"] = "3524033000000026011";
user_object["last_name"] = "sadasd";
users_array = [user_object];
request_body["users"] =users_array;
request_json = request_body.to_json
req.body = request_json.to_s
response=http.request(req)
status_code = response.code.to_i
headers = response.each_header.to_h
print status_code
print headers
unless response.body.nil?
print response.body
end
end
end
AddUser.new.execute
In the request, "@newuser.json" contains the sample input data.
Request JSON
- last_namestring, mandatory
Specify the last name of the user.
- emailstring, mandatory
Specify the email ID of the user.
- rolestring, mandatory
Specify the unique ID of the role you want to assign the user with. You can obtain the role ID from the Roles API.
- profilestring, mandatory
Specify the unique ID of the profile you want to assign the user with, to decide the user's level of access to CRM data. You can obtain the profile ID from the Profiles API.
Refer to Add Records API to know about the field types and limitations.
Sample Input
Copied{
"users": [
{
"role": "554023000000015969",
"first_name": "Patricia",
"email": "Patricia@abcl.com",
"profile": "554023000000015975",
"last_name": "Boyle"
}
]
}
Possible Errors
- INVALID_REQUESTHTTP 400
Cannot add user under CRM Plus account. Kindly use CRMPlus URL to add user.
Resolution: Adding a CRM Plus user through API is not supported. You can only add a CRM Plus user through the UI. Refer to the note section above. - LICENSE_LIMIT_EXCEEDEDHTTP 400
Request exceeds your license limit. Need to upgrade in order to add.
Resolution: The maximum number of users you can add per your CRM plan has exceeded. Please buy additional user licenses to add more users. - DUPLICATE_DATAHTTP 400
Failed to add user since same email id is already present
Resolution: You have entered a duplicate value for the email_id. Make sure you give unique values for the email_id and last_name fields. - MANDATORY_NOT_FOUNDHTTP 400
Last Name is required
Resolution: You have not specified one of the mandatory keys. Refer to request JSON section above. - INVALID_DATAHTTP 400
Invalid data. Valid values are comma/space/period/none.
Resolution: The key value specified is invalid. It can contain only the above mentioned special characters. - FORBIDDENHTTP 403
Permission denied
Resolution: Only the users with user profile is "administrator" can add new users. Contact your system administrator. - INVALID_URL_PATTERNHTTP 404
Please check if the URL trying to access is a correct one
Resolution: The request URL specified is incorrect. Specify a valid request URL. Refer to request URL section above. - OAUTH_SCOPE_MISMATCHHTTP 401
Unauthorized
Resolution: Client does not have ZohoCRM.users.CREATE scope. Create a new client with valid scope. Refer to scope section above. - NO_PERMISSIONHTTP 403
Permission denied to create
Resolution: The user does not have permission to create user records. Contact your system administrator. - INTERNAL_ERRORHTTP 500
Internal Server Error
Resolution: Unexpected and unhandled exception in the server. Contact support team. - INVALID_REQUEST_METHODHTTP 400
The http request method type is not a valid one
Resolution: You have specified an invalid HTTP method to access the API URL. Specify a valid request method. Refer to endpoints section above. - AUTHORIZATION_FAILEDHTTP 400
User does not have sufficient privilege to add new users
Resolution: The user does not have the permission to add users. Contact your system administrator.
Sample Response
Copied{
"users": [
{
"code": "SUCCESS",
"details": {
"id": "554023000000691003"
},
"message": "User added",
"status": "success"
}
]
}