Update Related Records

Purpose

To update the relation between the records.

Request URL

https://www.zohoapis.com/crm/v2/{module_api_name}/{record_id}/{related_list_api_name}/{related_record_id}

module_api_name - The API name of the module

record_id - Unique ID of the record

related_list_api_name - The API name of the related list. To get the API name of the related list, see Related Lists Meta Data

related_record_id - Unique ID of the related record

Supported relations
Campaigns - to - Leads, Contacts

Products - to - Leads, Accounts,
Contacts, Potentials, Price Books

Request Method

PUT

Scope

scope=ZohoCRM.modules.all
(or)
scope=ZohoCRM.modules.{module_name}.{operation_type}


Possible module names Possible operation types
leads, deals, contacts, accounts, products, campaigns, and pricebooksALL - Full access to records
WRITE - Edit related records
DELETE - Delete related records
Note
  • It is mandatory to send the sample data while adding relation between other modules.

  • To relate multiple records of a module to the parent module, you must pass individual JSON objects for each related record as shown in the example.

  • You can update a maximum of 100 related records per API call.

Sample Request: To add the relation between a Lead and Campaigns

In this request, campaigns with IDs 3652397000000327001 and 3652397000001854001 get associated with the lead with the ID 3652397000001829002.

 


				curl "https://www.zohoapis.com/crm/v2/Leads/3652397000001829002/Campaigns"
-X PUT
-d @updaterelatedlead.json
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"			

Sample Input


				{
	"data":[
		{
			"id":"3652397000000327001",
			"Member_Status":"Active"
		
		},
		{
			"id":"3652397000001854001",
			"Member_Status":"Planning"
		
		}]
}			

Sample Response


				{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "id": "3652397000000327001"
            },
            "message": "relation added",
            "status": "success"
        },
        {
            "code": "SUCCESS",
            "details": {
                "id": "3652397000001854001"
            },
            "message": "relation added",
            "status": "success"
        }
    ]
}			

Sample Request: To add the relation between Contacts and Deals

In this request, deal with ID 1000013559 gets associated with the contact with ID 1000017063.


				curl "https://www.zohoapis.com/crm/v2/Contacts/1000017063/Deals/1000013559"
-X PUT
-d @updaterelatedlead.json
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"			

Sample Input


				{
    "data": [
       {
            "Contact_Role": "1000000024229"
        }
    ]
}			

Sample Request: To add the relation between Products and Price Books

In this request, Price Book with ID 1000013559 gets associated with the Product with ID 1000017063.


				curl "https://www.zohoapis.com/crm/v2/Products/1000017063/Price_Books/1000013559"
-X PUT
-d @updaterelatedlead.json
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"			

Sample Input


				{
    "data": [
       {
            "list_price": 50.56
        }
    ]
}			

Sample Response


				{
    "data": [
       {
            "code": "SUCCESS",
            "details": {
                "id": "4000000039247"
            },
            "message": "relation added",
            "status": "success"
        }
    ]
}			

Sample Request: To add the relation between Leads and Campaigns

In this request, lead with ID 1234567l gets associated with the campaign with ID 963258l.


				ZCRMRecord record = ZCRMRecord.getInstance("Leads", 1234567l);//module api name with record id
ZCRMJunctionRecord relatedRecord = ZCRMJunctionRecord.getInstance("Campaigns", 963258l);
relatedRecord.setRelatedData("Status", "active");
APIResponse response = record.addRelation(relatedRecord);
String recStatus = response.getStatus(); //check status of the update relation			

Sample Input


				{
    "data": [
       {
            "Member_Status": "active"
        }
    ]
}			

Sample Request: To add the relation between Products and Pricebooks

In this request, pricebook with ID 880428000000261025l gets associated with the product with ID 880428000003772042l.


				ZCRMRecord record = ZCRMRecord.getInstance("Products",880428000003772042l);//module api name with record id
ZCRMJunctionRecord relatedRecord = ZCRMJunctionRecord.getInstance("Price_Books", 880428000000261025l);
relatedRecord.setRelatedData("list_price", 50.56);
APIResponse response = record.addRelation(relatedRecord);
String recStatus = response.getStatus(); //check status of the update relation			

Sample Input


				{
    "data": [
       {
            "list_price": 50.56
        }
    ]
}			

Sample Response


				{
    "data": [
       {
            "code": "SUCCESS",
            "details": {
                "id": "4000000039247"
            },
            "message": "relation added",
            "status": "success"
        }
    ]
}			

Sample Request: To add the relation between Products and Priocebooks


				try{
$parentRecord=ZCRMRecord::getInstance("Products", 410405000001446001);
$junctionRecord=ZCRMJunctionRecord::getInstance("Price_Books",
410405000001404743);
$junctionRecord->setRelatedData("list_price", 140);
$responseIns=$parentRecord->addRelation($junctionRecord);
echo "HTTP Code:".$responseIns->getHttpStatusCode();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
}catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
}			

Sample Input


				{
    "data": [
       {
            "list_price": 50.56
        }
    ]
}			

Sample Response


				{
    "data": [
       {
            "code": "SUCCESS",
            "details": {
                "id": "4000000039247"
            },
            "message": "relation added",
            "status": "success"
        }
    ]
}			

Sample Request: To add the relation between Leads and Products


				def add_relation(self):
        try:
            record = ZCRMRecord.get_instance('Leads', 3719520000000323002)  # module API Name, entityId
            junction_record = ZCRMJunctionRecord.get_instance("Products",3719520000000450002)  # module API Name, entityId
            resp = record.add_relation(junction_record)
            print(resp.status_code)
            print(resp.code)
            print(resp.details)
            print(resp.message)
            print(resp.status)
        except ZCRMException as ex:
            print(ex.status_code)
            print(ex.error_message)
            print(ex.error_code)
            print(ex.error_details)
            print(ex.error_content)			

Sample Input


				{
    "data": [
       {
            "Product_Name": MyProduct
        }
    ]
}			

Sample Response


				{
    "data": [
       {
            "code": "SUCCESS",
            "details": {
                "id": "4000000039247"
            },
            "message": "relation added",
            "status": "success"
        }
    ]
}			

Sample Request


				Syntax:
zoho.crm.updateRelatedRecord(<module String>,<recordID Long>,<parentModuleName String>,<parentRecordId Long>,<dataMap Map>,<connectionName String>,<userAccess Boolean>);
mandatory : module,recordID,parentModuleName,parentRecordId,dataMap

Sample Request:
resp = zoho.crm.updateRelatedRecord("Related_List_Name_2","7000000037119","Leads","7000000037002", Map());			

Sample Response


				{
    "data": [
       {
            "code": "SUCCESS",
            "details": {
                "id": "4000000039247"
            },
            "message": "relation added",
            "status": "success"
        }
    ]
}			

Sample Request


				ZCRMRecord recordIns = ZCRMRecord.GetInstance("Leads", 337216400000); //module api name with record id
ZCRMJunctionRecord relatedRecord = ZCRMJunctionRecord.GetInstance("Campaigns", 33721640000001); //RelatedList api name with RelatedList record id
relatedRecord.SetRelatedDetails("Status", "active");
APIResponse response = recordIns.AddRelation(relatedRecord);
String recStatus = response.Status; //check status of the update relation
//In the above example, lead with ID 337216400000 gets associated with the campaign with ID 33721640000001.			

Sample Input


				{
    "data": [
       {
            "Member_Status": "active"
        }
    ]
}			

Sample Response


				{
    "data": [
       {
            "code": "SUCCESS",
            "details": {
                "id": "4000000039247"
            },
            "message": "relation added",
            "status": "success"
        }
    ]
}