Insert Records using External ID

Purpose

To add new entities to a module using external ID.

 

Request Details

Request URL

{api-domain}/crm/v2/{module_api_name}

Supported modules

Leads, Accounts, Contacts, Deals, Campaigns, Tasks, Cases, Events, Calls, Solutions, Products, Vendors, Price Books, Quotes, Sales Orders, Purchase Orders, Invoices, Custom, and Activities

Possible operation types

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, accounts, contacts, deals, campaigns, tasks, cases, events, calls, solutions, products, vendors, pricebooks, quotes, salesorders, purchaseorders, invoices, custom, and notes

Possible operation types

ALL - Full access to the record
WRITE - Edit records in the module
CREATE - Create records in the module

Sample Request

Copiedcurl "https://zylkercorp.zohoplatform.com/crm/v2/{base_module_API_name}"
-X POST
-H "Authorization: Zoho-oauthtoken 100xx.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-H "X-EXTERNAL: {module_API_name}.{external_field_API_name}"
-d "@sample.json"
Associating a lookup record through an external field
  • In this example, Contacts is the base module's API name where Account_Name is a lookup field's API name in the Contacts module. External_Account_ID is the API name of the external field in the Accounts module. We will reference the external field's value in the Accounts module to create a record in the Contacts module.

Note

If you specify the value and the record ID of the external field for the lookup record, the system considers only the value of the external field when you give the X-EXTERNAL header. Without this header, the system considers only the record ID.

Sample Request

Copiedcurl "https://zylkercorp.zohoplatform.com/crm/v2/Contacts"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-H "X-EXTERNAL: Contacts.Account_Name.External_Account_ID"
-d "@sample.json"
1.0.0
Copied//Get instance of RecordOperations Class
let recordOperations = new ZCRM.Record.Operations();
//Get instance of BodyWrapper Class that will contain the request body
let request = new ZCRM.Record.Model.BodyWrapper();
//Array to hold Record instances
let recordsArray = [];
//Get instance of Record Class
let record = new ZCRM.Record.Model.Record();
/* Value to Record's fields can be provided in any of the following ways */
/*
 * Call addFieldValue method that takes two arguments
 * 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list.
 * 2 -> Value
 */
record.addFieldValue(ZCRM.Record.Model.Field.Leads.LAST_NAME, "JS SDK");
record.addFieldValue(ZCRM.Record.Model.Field.Leads.FIRST_NAME, "JS");
record.addFieldValue(ZCRM.Record.Model.Field.Leads.COMPANY, "ZCRM");
record.addFieldValue(ZCRM.Record.Model.Field.Leads.CITY, "City");
/*
 * Call addKeyValue method that takes two arguments
 * 1 -> A string that is the Field's API Name
 * 2 -> Value
 */
record.addKeyValue("Custom_field", "Value");
record.addKeyValue("Custom_field_2", "value");
record.addKeyValue("Date_1", new Date(2020,10,20));
record.addKeyValue("Subject", "AutomatedSDK");
let fileDetails = [];
let fileDetail = new ZCRM.Record.Model.FileDetails();
fileDetail.setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c32e98a84dfc2df549e9a46a78e8a27d753");
fileDetails.push(fileDetail);
fileDetail = new ZCRM.Record.Model.FileDetails();
fileDetail.setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c32e0063e7321b5b4ca878a934519e6cdb2");
fileDetails.push(fileDetail);
fileDetail = new ZCRM.Record.Model.FileDetails();
fileDetail.setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c323daf4780bfe0058133556f155795981f");
fileDetails.push(fileDetail);
record.addKeyValue("File_Upload", fileDetails);
// Used when GDPR is enabled
let dataConsent = new ZCRM.Record.Model.Consent();
dataConsent.setConsentRemarks("Approved.");
dataConsent.setConsentThrough("Email");
dataConsent.setContactThroughEmail(true);
dataConsent.setContactThroughSocial(false);
record.addKeyValue("Data_Processing_Basis_Details", dataConsent);
/** Following methods are being used only by Inventory modules */
let dealName = new ZCRM.Record.Model.Record();
dealName.addFieldValue(ZCRM.Record.Model.Field.Deals.ID, 3477067850014n);
record.addFieldValue(ZCRM.Record.Model.Field.Sales_Orders.DEAL_NAME, dealName);
let contactName = new ZCRM.Record.Model.Record();
contactName.addFieldValue(ZCRM.Record.Model.Field.Contacts.ID, 34096431074007n);
contactName.addFieldValue(ZCRM.Record.Model.Field.Sales_Orders.CONTACT_NAME, contactName);
let accountName = new ZCRM.Record.Model.Record();
accountName.addFieldValue(ZCRM.Record.Model.Field.Accounts.ID, 34770617969021n);
record.addFieldValue(ZCRM.Record.Model.Field.Sales_Orders.ACCOUNT_NAME, accountName);
record.addKeyValue("Discount", 10.5);
let inventoryLineItemArray = [];
let inventoryLineItem = new ZCRM.Record.Model.InventoryLineItems();
let lineItemProduct = new ZCRM.Record.Model.LineItemProduct();
lineItemProduct.setId(34770617247012n);
inventoryLineItem.setProduct(lineItemProduct);
inventoryLineItem.setQuantity(3);
inventoryLineItem.setProductDescription("productDescription");
inventoryLineItem.setListPrice(10.0);
inventoryLineItem.setDiscount("5.90");
let productLineTaxes = [];
let productLineTax = new ZCRM.Record.Model.LineTax();
productLineTax.setName("MyTax11");
productLineTax.setPercentage(20.0);
productLineTaxes.push(productLineTax);
inventoryLineItem.setLineTax(productLineTaxes);
inventoryLineItemArray.push(inventoryLineItem);
record.addKeyValue("Product_Details", inventoryLineItemArray);
let lineTaxes = [];
let lineTax = new ZCRM.Record.Model.LineTax();
lineTax.setName("MyTax1122");
lineTax.setPercentage(20.0);
lineTaxes.push(lineTax);
record.addKeyValue("$line_tax", lineTaxes);
/** End Inventory **/
/** Following methods are being used only by Activity modules */
record.addFieldValue(ZCRM.Record.Model.Field.Tasks.DESCRIPTION, "New Task");
record.addKeyValue("Currency", new Choice("INR"));
let remindAt = new ZCRM.Record.Model.RemindAt();
remindAt.setAlarm("FREQ=NONE;ACTION=EMAILANDPOPUP;TRIGGER=DATE-TIME:2021-07-03T12:30:00+05:30");
record.addFieldValue(ZCRM.Record.Model.Field.Tasks.REMIND_AT, remindAt);
let whoId = new ZCRM.Record.Model.Record();
whoId.setId(34770617955002n);
record.addFieldValue(ZCRM.Record.Model.Field.Tasks.WHO_ID, whoId);
record.addFieldValue(ZCRM.Record.Model.Field.Tasks.STATUS, new Choice("Waiting for Input"));
record.addFieldValue(ZCRM.Record.Model.Field.Tasks.DUE_DATE, new Date(2020,10,10));
record.addFieldValue(ZCRM.Record.Model.Field.Tasks.PRIORITY, new Choice("High"));
let whatId = new ZCRM.Record.Model.Record();
whatId.setId(34770617969021n);
record.addFieldValue(ZCRM.Record.Model.Field.Tasks.WHAT_ID, whatId);
record.addKeyValue("$se_module", "Accounts");
/** Recurring Activity can be provided in any activity module*/
let recurringActivity = new ZCRM.Record.Model.RecurringActivity();
recurringActivity.setRrule("FREQ=DAILY;INTERVAL=10;UNTIL=2020-08-14;DTSTART=2020-07-03");
record.addFieldValue(ZCRM.Record.Model.Field.Events.RECURRING_ACTIVITY, recurringActivity);
record.addFieldValue(ZCRM.Record.Model.Field.Events.DESCRIPTION, "My Event");
let startDateTime = new Date('October 15, 2020 05:35:32');
record.addFieldValue(ZCRM.Record.Model.Field.Events.START_DATETIME, startDateTime);
let participantsArray = [];
let participant = new ZCRM.Record.Model.Participants();
participant.setParticipant("test@zylkercorp.com");
participant.setType("email");
participantsArray.push(participant);
participant = new ZCRM.Record.Model.Participants();
participant.setParticipant("34770617634005");
participant.setType("contact");
participantsArray.push(participant);
record.addFieldValue(ZCRM.Record.Model.Field.Events.PARTICIPANTS, participantsArray);
record.addKeyValue("$send_notification", true);
record.addFieldValue(ZCRM.Record.Model.Field.Events.EVENT_TITLE, "New Automated Event");
let endDateTime = new Date('November 15, 2020 05:35:32');
record.addFieldValue(ZCRM.Record.Model.Field.Events.END_DATETIME, endDateTime);
let remindAt1 = new Date('October 15, 2020 04:35:32');
record.addFieldValue(ZCRM.Record.Model.Field.Events.REMIND_AT, remindAt1);
record.addFieldValue(ZCRM.Record.Model.Field.Events.CHECK_IN_STATUS, "PLANNED");
whatId = new ZCRM.Record.Model.Record();
whatId.setId(34770619074373n);
record.addFieldValue(ZCRM.Record.Model.Field.Tasks.WHAT_ID, whatId);
record.addKeyValue("$se_module", "Leads");
/** End Activity **/
/** Following methods are being used only by Price_Books module */
let pricingDetailsArray = [];
let pricingDetail = new ZCRM.Record.Model.PricingDetails();
pricingDetail.setFromRange(1.0);
pricingDetail.setToRange(5.0);
pricingDetail.setDiscount(2.0);
pricingDetailsArray.push(pricingDetail);
pricingDetail = new ZCRM.Record.Model.PricingDetails();
pricingDetail.addKeyValue("from_range", 6.0);
pricingDetail.addKeyValue("to_range", 11.0);
pricingDetail.addKeyValue("discount", 3.0);
pricingDetailsArray.push(pricingDetail);
record.addFieldValue(ZCRM.Record.Model.Field.Price_Books.PRICING_DETAILS, pricingDetailsArray);
record.addKeyValue("Email", "z2@zylkercorp.com");
record.addFieldValue(ZCRM.Record.Model.Field.Price_Books.DESCRIPTION, "TEST");
record.addFieldValue(ZCRM.Record.Model.Field.Price_Books.PRICE_BOOK_NAME, "book_name");
record.addFieldValue(ZCRM.Record.Model.Field.Price_Books.PRICING_MODEL, new Choice("Flat"));
/** End of Price_Books */
let tagsArray = [];
let tag = new ZCRM.Tag.Model.Tag();
tag.setName("Testtask");
tagsArray.push(tag);
record.setTag(tagsArray);
//Add Record instance to the array
recordsArray.push(record);
//Set the array to data in BodyWrapper instance
request.setData(recordsArray);
let trigger = [];
trigger.push("approval");
trigger.push("workflow");
trigger.push("blueprint");
//Set the array containing the trigger operations to be run
request.setTrigger(trigger);
let larId = "34096432157065";
//Set the larId
request.setLarId(larId);
let process = ["review_process"];
//Set the array containing the process to be run
request.setProcess(process);
//Call createRecords method that takes BodyWrapper instance and moduleAPIName as parameters
let response = await recordOperations.createRecords(moduleAPIName, request);

Sample Input

Copied{
    "data": [
        {
            "Last_Name": "ext contact 1",
            "Account_Name": {
                "External_Account_ID": "externalaccount1"
            }
        }
    ]
}

Sample Response

Copied{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "Modified_Time": "2020-10-22T01:35:09-11:00",
                "Modified_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                },
                "Created_Time": "2020-10-22T01:35:09-11:00",
                "id": "554023000001627036",
                "Created_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                }
            },
            "message": "record added",
            "status": "success"
        }
    ]
}
Creating an inventory module's record with external fields in the line items
  • In this example, we will create a quote by using the external values in the Product_Details section that comprises the associated product and the price book. So, Quotes is the base module's API name, the API names of the external fields in the Products and Price Books modules are External_Product_ID and External_Price_book_ID, respectively.

Sample Request

Copiedcurl "https://zylkercorp.zohoplatform.com/crm/v2/Quotes"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-H "X-EXTERNAL: Quotes.Product_Details.product.External_Product_ID, Quotes.Product_Details.book.External_Price_book_ID"
-d "@sample.json"

Sample Input

Copied{
    "data": [
        {
            "External_Quote_ID": "quote1",
            "Subject": "Quote 1",
            "Product_Details": [
                {
                    "product": {
                        "External_Product_ID": "12345678900"
                    },
                    "book": {
                        "External_Price_book_ID": "pricebook1"
                    },
                    "quantity": 100
                }
            ]
        }
    ]
}

Sample Response

Copied{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "Modified_Time": "2019-12-12T23:35:47+05:30",
                "Modified_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                },
                "Created_Time": "2019-12-12T23:35:47+05:30",
                "id": "111111000000133093",
                "Created_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                }
            },
            "message": "record added",
            "status": "success"
        }
    ]
}
Inserting a subform lookup record through an external field in the associated module
  • In this example, Subform_External is the API name of the subform in the Contacts module. It has a look up field to the Deals module. The Deals module has an external field External_Deal_ID. We will reference this external field in the subform and insert a record in the Contacts module.

Sample Request

Copiedcurl "https://zylkercorp.zohoplatform.com/crm/v2/Contacts"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-H "X-EXTERNAL: Contacts.Subform_External.Deal_Lookup.External_Deal_ID"
-d "@sample.json"

Sample Input

Copied{
    "data": [
        {
            "Last_Name": "Contact with a Subform",
            "Subform_External": [
                {
                    "Deal_Lookup": {
                        "External_Deal_ID": "userdeal1"
                    }
                }
            ]
        }
    ]
}

Sample Response

Copied{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "Modified_Time": "2019-12-12T23:35:47+05:30",
                "Modified_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                },
                "Created_Time": "2019-12-12T23:35:47+05:30",
                "id": "111111000000134014",
                "Created_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                }
            },
            "message": "record added",
            "status": "success"
        }
    ]
}
Inserting an Event record and associating the What_Id through an external field
  • In this example, External_Account_ID is the API name of the external field in the Accounts module. What_Id in the Events module takes the Account's name as its value. We will reference this external field in the Accounts module to the What_Id field and insert an event.

Sample Request

Copiedcurl "https://zylkercorp.zohoplatform.com/crm/v2/Events"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-H "X-EXTERNAL: Events.What_Id->Accounts.External_Account_ID"
-d "@sample.json"

Sample Input

Copied{
    "data": [
        {
            "se_module": "Accounts",
            "What_Id": {
                "External_Account_ID": "useraccount1"
            },
            "Event_Title": "Event Kaizen",
            "Start_DateTime": "2020-05-10T10:10:10+05:30",
            "End_DateTime": "2020-05-10T11:10:10+05:30"
        }
    ]
}

Sample Response

Copied{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "Modified_Time": "2019-12-12T23:35:47+05:30",
                "Modified_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                },
                "Created_Time": "2019-12-12T23:35:47+05:30",
                "id": "111111000000137001",
                "Created_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                }
            },
            "message": "record added",
            "status": "success"
        }
    ]
}
Inserting an Event record and associating the What_Id and Participant through external fields
  • In this example, External_Account_ID and External_Contact_ID are the API names of the external fields in the Accounts and Contacts modules, respectively. What_Id in the Events module takes the Account's name as its value. "participant" is a JSON object in the Participants array. We will reference these external values and insert an event.

Note

If you specify the value of the external field in the participant JSON object and the record ID of the external field in the Contacts module, the system considers only the value of the external field if you specify only the participant in the header.

Possible Errors

  • DUPLICATE_DATAHTTP 202

    The external field contains duplicate data.
    Resolution: Input unique data to the external field.

  • INVALID_DATAHTTP 202

    The external ID of the lookup field or the Price Book is incorrect
    Resolution: Specify the correct external ID. Refer to the "details" in the error response to know which external ID is incorrect.

Sample Request

Copiedcurl "https://zylkercorp.zohoplatform.com/crm/v2/Events"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-H "X-EXTERNAL: Events.What_Id->Accounts.External_Account_ID, Events.Participants.participant->Contacts.External_Contact_ID"
-d "@sample.json"

Sample Input

Copied{
    "data": [
        {
            "External_Event_ID": "Event Kaizen 1",
            "Last_Name": "Contact 1",
            "Participants": [
                {
                    "type": "contact",
                    "participant": {
                        "External_Contact_ID": "participant1"
                    }
                }
            ],
            "What_Id": {
                "External_Account_ID": "useraccount1"
            },
            "$se_module": "Accounts",
            "Event_Title": "Kaizen 1",
            "Start_DateTime": "2020-05-10T10:10:10+05:30",
            "End_DateTime": "2020-05-10T11:10:10+05:30"
        }
    ]
}

Sample Response

Copied{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "Modified_Time": "2019-12-12T23:35:47+05:30",
                "Modified_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                },
                "Created_Time": "2019-12-12T23:35:47+05:30",
                "id": "111111000000139016",
                "Created_By": {
                    "name": "Patricia Boyle",
                    "id": "554023000000235011"
                }
            },
            "message": "record added",
            "status": "success"
        }
    ]
}