Get Assignment Rules

Purpose

To fetch the assignment rules in your org.

Request Details

Request URL

All - {api-domain}/crm/{version}/settings/automation/assignment_rules
Specific - {api-domain}/crm/{version}/settings/automation/assignment_rules/{rule_id}

Supported modules

Leads, Accounts, Contacts, Deals, Tasks, Cases, and Custom

Header

Authorization: Zoho-oauthtoken <access_token>

Scope

scope=ZohoCRM.settings.assignment_rules.{{operation-type}}

Possible operation types

ALL - Full access to data
READ - Get data from the module

Parameters
  • modulestring, mandatory (mandatory when you fetch a specific assignment rule)

    The API name of the module you want to fetch the assignment rule from. Supported modules are Leads, Contacts, Accounts, Deals, and Custom.

Possible Errors

  • BAD_REQUESTHTTP 400

    The request method specified is invalid.
    Resolution: Specify the request method as GET.

  • REQUIRED_PARAM_MISSINGHTTP 400

    One of the expected parameter is missing
    Resolution: Include the module parameter in the request when you fetch a specific assignment rule.

  • OAUTH_SCOPE_MISMATCHHTTP 401

    The token does not have the scope ZohoCRM.settings.ALL.
    Resolution: Create a token with the scope ZohoCRM.settings.ALL.

  • NO_PERMISSIONHTTP 403

    You do not have the permission to read the assignment rules.
    Resolution: Contact your administrator.

  • INVALID_URL_PATTERNHTTP 404

    The request URL has syntactical errors.
    Resolution: Correct the syntactical errors in the request URL.

Sample Request

Copiedcurl "https://www.zohoapis.com/crm/v2.1/settings/automation/assignment_rules"
-X GET
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
4.0.04.x
Copied//Get instance of AssignmentRulesOperations Class
$assignmentRulesOperations = new AssignmentRulesOperations();
//Call getAssignmentRules method
$response = $assignmentRulesOperations->getAssignmentRules();


$paramInstance = new ParameterMap();
$paramInstance->add(GetAssignmentRuleParam::module(), "leads");
//Get instance of AssignmentRulesOperations Class
$assignmentRulesOperations = new AssignmentRulesOperations();
//Call getAssignmentRule method that takes ruleId and ParameterMap instance as parameter
$response = $assignmentRulesOperations->getAssignmentRule($ruleId, $paramInstance);
Copied<?php
class GetAssignmentRules{
    
    public function execute(){
        $curl_pointer = curl_init();
        
        $curl_options = array();
        $url = "https://www.zohoapis.com/crm/v2.1/settings/automation/assignment_rules?";
        $parameters = array();
        $parameters["module"]="Leads";

        foreach ($parameters as $key=>$value){
            $url =$url.$key."=".$value."&";
        }
        $curl_options[CURLOPT_URL] = $url;
        $curl_options[CURLOPT_RETURNTRANSFER] = true;
        $curl_options[CURLOPT_HEADER] = 1;
        $curl_options[CURLOPT_CUSTOMREQUEST] = "GET";
        $headersArray = array();
        $headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " ."1000.30f3a589XXXXXXXXXXXXXXXXXXX4077.dc5XXXXXXXXXXXXXXXXXXXee9e7c171c";
        $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 GetAssignmentRules())->execute();

Sample Response

Copied{
    "assignment_rules": [
        {
            "created_time": "2020-04-12T00:00:00+05:30",
            "modified_time": "2021-02-26T12:45:14+05:30",
            "default_assignee": {
                "name": "Patricia Boyle",
                "id": "3652397000000186017"
            },
            "module": {
                "api_name": "Leads",
                "id": "3652397000000002175"
            },
            "name": "Lead Assignment Rule",
            "modified_by": {
                "name": "Patricia Boyle",
                "id": "3652397000000186017"
            },
            "description": "Assign the Leads to the Owners based on these criteria.",
            "id": "3652397000002045001",
            "created_by": {
                "name": "Patricia Boyle",
                "id": "3652397000000186017"
            }
        }
    ]
}