Delete Related Records Using External ID

Purpose

To delete the related list records using external IDs.

Request Details

Request URL

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

Header

Authorization: Zoho-oauthtoken d92d4xxxxxxxxxxxxx15f52

X-EXTERNAL: {module_API_name}.{external_field_API_name}

Scope

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

Possible module names

leads, deals, contacts, accounts, products, campaigns, and pricebooks

Possible operation types

ALL - Full access to the related records
WRITE - Edit related records
DELETE - Delete related records from the module

Sample Request

Copiedcurl "https://www.zohoapis.com/crm/v2/Contacts/extcontact3/Deals/extdeal3"
-X DELETE
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-H "X-EXTERNAL: Contacts.External_Contact_ID"
3.0.0
CopiedString moduleAPIName = "Leads";
Long recordId = "3477061000005177002";
String relatedListAPIName = "Products";
List<Long> relatedListIds = new ArrayList<Long>(Arrays.asList(3477061000005919001L, 3477061000005917011L));

//Get instance of RelatedRecordsOperations Class that takes relatedListAPIName, recordId and moduleAPIName as parameter
RelatedRecordsOperations relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, recordId, moduleAPIName);

//Get instance of ParameterMap Class
ParameterMap paramInstance = new ParameterMap();

for (Long relatedListId: relatedListIds) {
    paramInstance.add(DelinkRecordsParam.IDS, relatedListId);
}

//Call delinkRecords method that takes paramInstance instance as parameter.
APIResponse < ActionHandler > response = relatedRecordsOperations.delinkRecords(paramInstance);
3.0.0
Copied//Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
$relatedRecordsOperations = new RelatedRecordsOperations($relatedListAPIName,  $recordId,  $moduleAPIName);
//Get instance of ParameterMap Class
$paramInstance = new ParameterMap();
foreach($relatedListIds as $relatedListId)
{
        $paramInstance->add(DelinkRecordsParam::ids(), $relatedListId);
}
//Call delinkRecords method that takes paramInstance instance as parameter.
$response = $relatedRecordsOperations->delinkRecords($paramInstance);
3.0.0
Copied//Get instance of RelatedRecordsOperations Class that takes relatedListAPIName, recordId and moduleAPIName as parameter
RelatedRecordsOperations relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, recordId, moduleAPIName);
//Get instance of ParameterMap Class
ParameterMap paramInstance = new ParameterMap();
foreach(long relatedListId in relatedListIds)
{
    paramInstance.Add(DelinkRecordsParam.IDS, relatedListId);
}
//Call DelinkRecords method that takes paramInstance instance as parameter.
APIResponse<ActionHandler> response = relatedRecordsOperations.DelinkRecords(paramInstance);
3.0.0
Copied# Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
related_records_operations = RelatedRecordsOperations(related_list_api_name, record_id, module_api_name)
# Get instance of ParameterMap Class
param_instance = ParameterMap()
for related_list_id in related_list_ids:
    param_instance.add(DelinkRecordsParam.ids, related_list_id)
# Call delink_records method that takes ParameterMap instance as parameter.
response = related_records_operations.delink_records(param_instance)


# Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
related_records_operations = RelatedRecordsOperations(related_list_api_name, record_id, related_list_api_name)
# Call delink_record method that takes related_list_id as parameter.
response = related_records_operations.delink_record(related_list_id)
1.0.0
Copied//Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
let relatedRecordsOperations = new RelatedRecordsOperations(relatedListAPIName, recordId, moduleAPIName);
//Get instance of ParameterMap Class
let paramInstance = new ParameterMap();
/* Possible parameters of Delink Records operation */
for(let relatedListId of relatedListIds) {
    await paramInstance.add(DelinkRecordsParam.IDS, relatedListId);
}
//Call delinkRecords method that takes ParameterMap instance as parameter.
let response = await relatedRecordsOperations.delinkRecords(paramInstance);
2.0.0
Copied# Get instance of ParameterMap Class
pm = ParameterMap.new

related_list_ids.each do |related_id|
  pm.add(RelatedRecords::RelatedRecordsOperations::DelinkRecordsParam.ids, related_id)
end
# Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
rro = RelatedRecords::RelatedRecordsOperations.new(related_list_api_name , record_id, module_api_name)
# Call delink_records method that takes ParameterMap instance as parameter.
response = rro.delink_records(pm)


# Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
rro = RelatedRecords::RelatedRecordsOperations.new(related_list_api_name , record_id, module_api_name)
# Call delink_record method that takes related_list_id as parameter.
response = rro.delink_record(related_record_id)
1.0.0
Copied//Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
let relatedRecordsOperations = new ZCRM.RelatedRecord.Operations(relatedListAPIName, recordId, moduleAPIName);
//Get instance of ParameterMap Class
let paramInstance = new ParameterMap();
/* Possible parameters of Delink Records operation */
for(let relatedListId of relatedListIds) {
    await paramInstance.add(ZCRM.RelatedRecord.Model.DelinkRecordsParam.IDS, relatedListId);
}
//Call delinkRecords method that takes ParameterMap instance as parameter.
let response = await relatedRecordsOperations.delinkRecords(paramInstance);






//Get instance of RelatedRecordsOperations Class that takes moduleAPIName, recordId and relatedListAPIName as parameter
let relatedRecordsOperations = new ZCRM.RelatedRecord.Operations(relatedListAPIName, recordId, moduleAPIName);
//Call delinkRecord method that takes relatedListId as parameter.
let response = await relatedRecordsOperations.delinkRecord(relatedListId);
De-linking a Contact and a Deal using their external IDs
  • In this example, extcontact3 and extdeal3 are the values of the external fields External_Contact_ID and External_Deal_ID in the Contacts and Deals modules, respectively. we will reference these values to delink the deal from the contact.

Possible Errors

  • INVALID_DATAHTTP 400

    You have specified either an incorrect external ID of the related record or the base module's record. The details key in the response gives you the name of the external field whose ID is incorrect.
    Resolution: Specify the correct external ID of the related record.

Sample Response

Copied{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "id": "111111000000094040"
            },
            "message": "relation removed",
            "status": "success"
        }
    ]
}