a. Record ID of the Owner
To assign an owner to a record, you must know the ID of the owner.
Make a GET Users API call to fetch the list of all users in your org.
Request URL: {{api-domain}}/crm/v2/users
Request method: GET
Here is a snippet of the response.
The "id" key represents the unique ID of the user record.
b. API Name and field type of the owner field to use in the input
API Name
You can find the API name of the owner field in two ways
i. From the UI
1. Go to Setup > Developer Space > APIs > API Names > Choose the module.
2. For Leads, the API Name of the Lead Owner field is Owner.
ii. Through API
2. Search for the field label Lead Owner in the response.
3. The value of the key api_name represents the API Name of the Lead Owner field.
4. The value of the key json_type represents the type of the JSON input you must pass for that field.
Here, the Lead Owner field accepts data as a JSON object.
Now that we have the required details, let us see how to construct the input body to insert a lead and assign the owner of that lead record.
Last_Name is the system-defined mandatory field in the Leads module.
Owner is a JSON Object.
Request URL: {{api-domain}}/crm/v2/Leads
Request method: POST
Sample Input
{
"data": [
{
"Last_Name": "Kaizen #28",
"Owner":{
"id":"3652397000000281001"//Record ID of the user from the GET Users API
}
}
]
}
|
Here is the response.
Request URL: {{api-domain))/crm/v2/Leads/3652397000002043003
Request method: GET
Here is the response.
As you can see, the Lead is assigned to the owner.
Note
If you do not specify the owner, the system assigns the current user as the owner of the record.
2. Updating the record owner
As discussed in the above section, the Owner field is a JSON object.
Here is a sample input.
{
"data": [
{
"Owner": {
"id": "3652397000000186017"//Record ID of the new owner
}
}
]
}
|
3. Automatically changing the Record Owner
In CRM, while record creation, the system assigns the current user as the owner of a record, by default. If you want to assign leads to other owners automatically without the need to pass the Owner details in the API, you can write a custom function to achieve the same.
Your custom function must have the logic to assign owners to records based on the desired criteria.
Therefore, whenever a lead is created in CRM, it must trigger the custom function that assigns the lead to the right owner.
We hope you found this post useful. Let us know your thoughts in the comment section, or write to us at support@zohocrm.com.
Cheers!