Delete Records Using External ID
Purpose
To delete the records in a module using external IDs.
Request Details
Request URL
https://www.zohoapis.com/crm/v2/{module_api_name}
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 records
WRITE - Edit records in the module
DELETE - Delete records from the module
Deleting a record using an external ID
In this example, we will delete the record in the Contacts module with the external value extcontact3 in the external field "External_Contact_ID".
Sample Request
Copiedcurl "https://www.zohoapis.com/crm/v2/Contacts/extcontact3"
-X DELETE
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-H "X-EXTERNAL: Contacts.External_Contact_ID"
Copied//API Name of the module
String moduleAPIName = "Leads";
List<Long> recordIds = new ArrayList<Long>(Arrays.asList(3477061000005908033L,3477061000005908017L;,3477061000005908001L));
//Get instance of RecordOperations Class
RecordOperations recordOperations = new RecordOperations();
//Get instance of ParameterMap Class
ParameterMap paramInstance = new ParameterMap();
for (Long id: recordIds) {
paramInstance.add(DeleteRecordsParam.IDS, id);
}
paramInstance.add(DeleteRecordsParam.WF_TRIGGER, false);
HeaderMap headerInstance = new HeaderMap();
//Call deleteRecords method that takes moduleAPIName and paramInstance as parameter.
APIResponse < ActionHandler > response = recordOperations.deleteRecords(moduleAPIName, paramInstance,headerInstance);
Copied//Get instance of RecordOperations Class
$recordOperations = new RecordOperations();
//Get instance of ParameterMap Class
$paramInstance = new ParameterMap();
foreach($recordIds as $id)
{
$paramInstance->add(DeleteRecordsParam::ids(), $id);
}
// $paramInstance->add(DeleteRecordsParam::wfTrigger(), "true");
$headerInstance = new HeaderMap();
//Call deleteRecord method that takes ModuleAPIName and recordId as parameter.
$response = $recordOperations->deleteRecords($moduleAPIName,$paramInstance,$headerInstance);
Copied//Get instance of RecordOperations Class
RecordOperations recordOperations = new RecordOperations();
//Get instance of ParameterMap Class
ParameterMap paramInstance = new ParameterMap();
paramInstance.Add(DeleteRecordParam.WF_TRIGGER, "false");
HeaderMap headerInstance = new HeaderMap();
//Call DeleteRecord method that takes paramInstance, ModuleAPIName and recordId as parameter.
APIResponse<ActionHandler> response = recordOperations.DeleteRecord(recordId, moduleAPIName, paramInstance,headerInstance);
Copied# Get instance of RecordOperations Class
record_operations = RecordOperations()
# Get instance of ParameterMap Class
param_instance = ParameterMap()
# Possible parameters for Delete Records operation
param_instance.add(DeleteRecordsParam.wf_trigger, "true")
for record_id in record_ids:
param_instance.add(DeleteRecordsParam.ids, record_id)
header_instance = HeaderMap()
# Call deleteRecords method that takes param_instance and module_api_name as parameter.
response = record_operations.delete_records(module_api_name, param_instance,headerInstance)
# Get instance of RecordOperations Class
record_operations = RecordOperations()
# Get instance of ParameterMap Class
param_instance = ParameterMap()
# Possible parameters for Delete Record operation
param_instance.add(DeleteRecordParam.wf_trigger, "true")
header_instance = HeaderMap()
# Call deleteRecord method that takes param_instance, module_api_name and record_id as parameter.
response = record_operations.delete_record(record_id, module_api_name, param_instance,headerInstance)
Copied//Get instance of RecordOperations Class
let recordOperations = new RecordOperations();
//Get instance of ParameterMap Class
let paramInstance = new ParameterMap();
/* Possible parameters for Delete Records operation */
for(let recordId of recordIds) {
await paramInstance.add(DeleteRecordsParam.IDS, recordId);
}
await paramInstance.add(DeleteRecordsParam.WF_TRIGGER, "true");
//Get instance of HeaderMap Class
let headerInstance = new HeaderMap();
//Call deleteRecords method that takes paramInstance and moduleAPIName as parameter.
let response = recordOperations.deleteRecords(moduleAPIName, paramInstance,headerInstance);
Copiedrecords = []
# Get instance of ParameterMap Class
pm = ParameterMap.new
# Possible parameters for Delete Records operation
record_ids.each do |record_id|
pm.add(Record::RecordOperations::DeleteRecordsParam.ids, record_id)
end
# Get instance of RecordOperations Class
rr = Record::RecordOperations.new
# Call deleteRecords method that takes param_instance and module_api_name as parameter.
response = rr.delete_records(module_api_name,pm)
records = []
# Get instance of ParameterMap Class
pm = ParameterMap.new
pm.add(Record::RecordOperations::DeleteRecordParam.wf_trigger, false)
# Get instance of RecordOperations Class
rr = Record::RecordOperations.new
# Get instance of HeaderMap Class
hm = HeaderMap.new
# Call deleteRecord method that takes param_instance, module_api_name and record_id as parameter.
response = rr.delete_record(record_id, module_api_name, pm,hm)
Copied//Get instance of RecordOperations Class
let recordOperations = new ZCRM.Record.Operations();
//Get instance of ParameterMap Class
let paramInstance = new ParameterMap();
/* Possible parameters for Delete Records operation */
for(let recordId of recordIds) {
await paramInstance.add(ZCRM.Record.Model.DeleteRecordsParam.IDS, recordId);
}
await paramInstance.add(ZCRM.Record.Model.DeleteRecordsParam.WF_TRIGGER, "true");
//Call deleteRecords method that takes paramInstance and moduleAPIName as parameter.
let response = await recordOperations.deleteRecords(moduleAPIName, paramInstance);
//Get instance of RecordOperations Class
let recordOperations = new ZCRM.Record.Operations();
//Get instance of ParameterMap Class
let paramInstance = new ParameterMap();
//Possible parameters for Delete Record operation
await paramInstance.add(ZCRM.Record.Model.DeleteRecordParam.WF_TRIGGER, "true");
//Call deleteRecord method that takes paramInstance, ModuleAPIName and recordId as parameter.
let response = await recordOperations.deleteRecord(recordId, moduleAPIName, paramInstance);
Sample Response
Copied{
"data": [
{
"code": "SUCCESS",
"details": {
"External_Contact_ID": "extcontact4",
"id": "111111000000110002"
},
"message": "record deleted",
"status": "success"
}
]
}
Deleting the records using the "ids" parameter
In this example, we have used the "ids" parameter with values as the values of the external field in the Contacts module.
Sample Request
Copiedcurl "https://www.zohoapis.com/crm/v2/Contacts?ids=extcontact3,extcontact4"
-X DELETE
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-H "X-EXTERNAL: Contacts.External_Contact_ID"
Sample Response
Copied{
"data": [
{
"code": "SUCCESS",
"details": {
"External_Contact_ID": "extcontact3",
"id": "111111000000101047"
},
"message": "record deleted",
"status": "success"
},
{
"code": "SUCCESS",
"details": {
"External_Contact_ID": "extcontact4",
"id": "111111000000101018"
},
"message": "record deleted",
"status": "success"
}
]
}
Possible Errors
- INVALID_DATAHTTP 400
The value of the external field is invalid.
Resolution: Specify the correct external ID of the record.