Update Records

Purpose

To update existing entities in the module.

Request Details

Request URL

https://www.zohoapis.com/bigin/v1/{module_api_name}
Scope

scope=ZohoBigin.modules.ALL
(or)
scope=ZohoBigin.modules.{module_name}.{operation_type}

Possible module names

Accounts(companies in Bigin), contacts, deals, tasks, events, calls, products and notes

Possible operation types

ALL - Full access to the record
WRITE - Edit records in the module
UPDATE - Update records in the module

Sample Request

Copiedcurl "https://www.zohoapis.com/bigin/v1/Contacts"
-X PUT
-d "@updatecontact.json"
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
Copied$moduleIns=ZCRMRestClient::getInstance()->getModuleInstance("Invoices"); //to get the instance of the module
$records=array();

/** Following methods are used only by Inventory modules **/

$record=ZCRMRecord::getInstance("Invoices","554023000000527034"); //to get the instance of the record
$record->setFieldValue("Subject","Invoice3");  //This function use to set FieldApiName and value similar to all other FieldApis and Custom field
$record->setFieldValue("Account_Name","554023000000366005");
$lineItem=ZCRMInventoryLineItem::getInstance("554023000000504001");  //To get ZCRMInventoryLineItem instance
$lineItem->setDescription("Product_description");  //To set line item description
$lineItem ->setDiscount(20);  //To set line item discount
$lineItem->setListPrice(3412);  //To set line item list price

$taxInstance1=ZCRMTax::getInstance("VAT"); //to get the tax instance
$taxInstance1->setPercentage(20); //to set the tax percentage
$taxInstance1->setValue(50); //to set the  tax value
$lineItem->addLineTax($taxInstance1); //to add the tax to the line item

$lineItem->setQuantity(101);  //To set product quantity to this line item
$record->addLineItem($lineItem); //to add the line item to the record of invoice

array_push($records, $record); //pushing the record to the array

//$record=ZCRMRecord::getInstance("{module_api_name}","{record_id}");
//$record->setFieldValue("Subject","test54");  //This function use to set FieldApiName and value similar to all other FieldApis and Custom field
//$record->setFieldValue("Account_Name","{account_id}");

//array_push($records, $record); //pushing the record to the array

$responseIn=$moduleIns->updateRecords($records); //updating the records

foreach($responseIn->getEntityResponses() as $responseIns){
    echo "HTTP Status Code:".$responseIn->getHttpStatusCode();  //To get http response code
    echo "Status:".$responseIns->getStatus();  //To get response status
    echo "Message:".$responseIns->getMessage();  //To get response message
    echo "Code:".$responseIns->getCode();  //To get status code
    echo "Details:".json_encode($responseIns->getDetails());
}
Copieddef update_records(self):
    try:
        record_ins_list = list()
        record = zcrmsdk.ZCRMRecord.get_instance('Invoices')  # Module API Name
        record.set_field_value('id', 554023000000527034) # record id
        record.set_field_value('Subject', 'Invoice')  # This method use to set FieldApiName and value similar to all other FieldApis and Custom field
        record.set_field_value('Account_Name', 'Zylker')
        record.set_field_value('Price_Book_Name', 'Price_book_1')
        record.set_field_value('Pricing_Model', 'Flat')
        record.set_field_value('Event_Title', 'Title')
        record.set_field_value('Start_DateTime', '2018-09-04T15:52:21+05:30')
        record.set_field_value('End_DateTime', '2019-01-04T15:52:21+05:30')
        record.set_field_value('Product_Name', 'product_1')
        user = zcrmsdk.ZCRMUser.get_instance(347706100001, 'Patricia Boyle')  # user id and user name
        record.set_field_value('Owner', user)

        # Following methods are used only by Inventory modules
        taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")

        record.tax_list.append(taxIns)

        pricing = zcrmsdk.ZCRMPriceBookPricing(None)
        pricing.to_range = 5
        pricing.from_range = 1
        pricing.discount = 0
        record.price_details.append(pricing)

        pricing = zcrmsdk.ZCRMPriceBookPricing(None)
        pricing.to_range = 11
        pricing.from_range = 6
        pricing.discount = 1
        record.price_details.append(pricing)

        pricing = zcrmsdk.ZCRMPriceBookPricing(None)
        pricing.to_range = 17
        pricing.from_range = 12
        pricing.discount = 2
        record.price_details.append(pricing)

        # participants = zcrmsdk.ZCRMEventParticipant(3477061000000,'contact')  # Contacts record id and participant type
        # record.participants.append(participants)

        # participants = zcrmsdk.ZCRMEventParticipant('usermail@domain.com', 'email')
        # participants.email = 'usermail@domain.com'
        # participants.name = 'username'
        # participants.is_invited = 'true'
        # record.participants.append(participants)

        line_item = zcrmsdk.ZCRMInventoryLineItem.get_instance(zcrmsdk.ZCRMRecord.get_instance('Products', 347706100001))  # module api name and record id
        line_item.discount = 10
        line_item.list_price = 8
        line_item.description = 'Product Description'
        line_item.quantity = 100
        line_item.tax_amount = 2.5
        taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")
        taxIns.percentage = 5
        line_item.line_tax.append(taxIns)
        record.add_line_item(line_item)

        line_tax = []
        line_tax_row1 = {}
        line_tax_row1['percentage'] = 12.5
        line_tax_row1['name'] = 'Sales Tax'
        line_tax.append(line_tax_row1)
        line_tax_row2 = {}
        line_tax_row2['percentage'] = 8.5
        line_tax_row2['name'] = 'Common Tax'
        line_tax.append(line_tax_row2)

        record.set_field_value('$line_tax', line_tax)
        record_ins_list.append(record)

        resp = zcrmsdk.ZCRMModule.get_instance('Invoices').update_records(record_ins_list)
        print(resp.status_code)
        entity_responses = resp.bulk_entity_response
        for entity_response in entity_responses:
            print(entity_response.details)
            print(entity_response.status)
            print(entity_response.message)
            print(entity_response.data.entity_id)
            print(entity_response.data.created_by.id)
            print(entity_response.data.created_time)
            print(entity_response.data.modified_by.id)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code) 
        print(ex.error_message)
        print(ex.error_code)
        print(ex.error_details)
        print(ex.error_content)
CopiedSyntax:
<variable> =zoho.crm.updateRecord(<module_name>, <record_ID>, <record_value>, [<query_value>], [<connection>]);
mandatory: module_name, record_id

Sample Request:
leadinfo = 
 {
 "Company":"Zylker", 
 "Last_Name":"Stewart", 
 "Phone":"9876XXXXXX",
 "Email":"stewart@zylker.com"
 }; 

response = zoho.crm.updateRecord("Leads",23033XXXXXXXXXXXXXX,leadinfo);
Copiedpublic void UpdateRecords()
{
    List<ZCRMRecord> listRecord = new List<ZCRMRecord>();
    ZCRMRecord record;

    record = new ZCRMRecord("Invoices"); //To get ZCRMRecord instance
    record.SetFieldValue("id", 3372164000001904002);
    record.SetFieldValue("Subject", "UpdateInvoice4"); //This method use to set FieldApiName and value similar to all other FieldApis and Custom field
    record.SetFieldValue("Account_Name", 3372164000001855101);
    record.SetFieldValue("Company", "KK");
    record.SetFieldValue("Last_Name", "User");
    record.SetFieldValue("Customfield", "CustomFieldValue");
    record.SetFieldValue("Price_Book_Name", "Price_Book_Name");

    /** Following methods are being used only by Inventory modules */
    ZCRMPriceBookPricing pricing;

    pricing = new ZCRMPriceBookPricing
    {
        ToRange = 5,
        FromRange = 1,
        Discount = 0
    };
    record.AddPriceDetail(pricing);

    pricing = new ZCRMPriceBookPricing
    {
        ToRange = 11,
        FromRange = 6,
        Discount = 1
    };
    record.AddPriceDetail(pricing);

    pricing = new ZCRMPriceBookPricing
    {
        ToRange = 17,
        FromRange = 12,
        Discount = 2
    };
    record.AddPriceDetail(pricing);

    pricing = new ZCRMPriceBookPricing
    {
        ToRange = 23,
        FromRange = 18,
        Discount = 3
    };
    record.AddPriceDetail(pricing);

    record.SetFieldValue("Pricing_Model", "Flat"); 
    ZCRMTax linetax;
    linetax = ZCRMTax.GetInstance("Sales Tax");
    linetax.Percentage = 12.5;
    record.AddTax(linetax);

    ZCRMRecord product = ZCRMRecord.GetInstance("Products", 3372164000000190001); // product instance

    ZCRMInventoryLineItem lineItem = new ZCRMInventoryLineItem(product)
    {
        Description = "Product_description", //To set line item description
        Discount = 5, //To set line item discount
        ListPrice = 100 //To set line item list price

    }; //To get ZCRMInventoryLineItem instance
    lineItem.DiscountPercentage = 10;
    ZCRMTax taxInstance = ZCRMTax.GetInstance("Sales Tax"); //To get ZCRMTax instance
    taxInstance.Percentage = 2; //To set tax percentage
    taxInstance.Value = 50; //To set tax value
    lineItem.AddLineTax(taxInstance); //To set line tax to line item

    taxInstance = ZCRMTax.GetInstance("Vat");
    taxInstance.Percentage = 12;
    taxInstance.Value = 50;

    lineItem.AddLineTax(taxInstance);
    lineItem.Quantity = 200; //To set product quantity to this line item

    record.AddLineItem(lineItem); //The line item set to the record object
    /** End Inventory **/

    listRecord.Add(record);


    record = new ZCRMRecord("Invoices"); //To get ZCRMRecord instance
    record.SetFieldValue("id", 3372164000001904001);
    record.SetFieldValue("Subject", "UpdateInvoice4"); //This method use to set FieldApiName and value similar to all other FieldApis and Custom field
    record.SetFieldValue("Account_Name", 3372164000001855101);
    record.SetFieldValue("Company", "KK");
    record.SetFieldValue("Last_Name", "User");
    record.SetFieldValue("Customfield", "CustomFieldValue");
    record.SetFieldValue("Price_Book_Name", "Price_Book_Name");

    /** Following methods are being used only by Inventory modules */
    ZCRMPriceBookPricing pricing1;

    pricing1 = new ZCRMPriceBookPricing
    {
        ToRange = 5,
        FromRange = 1,
        Discount = 0
    };
    record.AddPriceDetail(pricing1);

    pricing1 = new ZCRMPriceBookPricing
    {
        ToRange = 11,
        FromRange = 6,
        Discount = 1
    };
    record.AddPriceDetail(pricing1);

    pricing1 = new ZCRMPriceBookPricing
    {
        ToRange = 17,
        FromRange = 12,
        Discount = 2
    };
    record.AddPriceDetail(pricing1);

    pricing1 = new ZCRMPriceBookPricing
    {
        ToRange = 23,
        FromRange = 18,
        Discount = 3
    };
    record.AddPriceDetail(pricing1);

    record.SetFieldValue("Pricing_Model", "Flat");
    linetax = ZCRMTax.GetInstance("Sales Tax");
    linetax.Percentage = 12.5;
    record.AddTax(linetax);

    ZCRMRecord product1 = ZCRMRecord.GetInstance("Products", 3372164000000190001); // product instance

    ZCRMInventoryLineItem lineItem1 = new ZCRMInventoryLineItem(product1)
    {
        Description = "Product_description", //To set line item description
        Discount = 5, //To set line item discount
        ListPrice = 100 //To set line item list price

    }; //To get ZCRMInventoryLineItem instance
    lineItem1.DiscountPercentage = 10;
    ZCRMTax taxInstance11 = ZCRMTax.GetInstance("Sales Tax"); //To get ZCRMTax instance
    taxInstance11.Percentage = 2; //To set tax percentage
    taxInstance11.Value = 50; //To set tax value
    lineItem1.AddLineTax(taxInstance11); //To set line tax to line item

    taxInstance11 = ZCRMTax.GetInstance("Vat");
    taxInstance11.Percentage = 12;
    taxInstance11.Value = 50;

    lineItem1.AddLineTax(taxInstance11);
    lineItem1.Quantity = 500; //To set product quantity to this line item

    record.AddLineItem(lineItem1); //The line item set to the record object
    /** End Inventory **/

    listRecord.Add(record);

    ZCRMModule moduleIns = ZCRMModule.GetInstance("Invoices"); //To get the Module instance
    BulkAPIResponse<ZCRMRecord> responseIns = moduleIns.UpdateRecords(listRecord); //To call the Update record method
    Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode); //To get Update record http response code
    foreach (EntityResponse response in responseIns.BulkEntitiesResponse)
    {
        Console.WriteLine("Status:" + response.Status); //To get Update record response status
        Console.WriteLine("Message:" + response.Message); //To get Update record response message
        Console.WriteLine("Details:" + response.ResponseJSON); //To get Update record response details
        ZCRMRecord record1 = (ZCRMRecord)response.Data;
        Console.WriteLine(record1.EntityId); //To get inserted record id
        Console.WriteLine(record1.CreatedTime);
        Console.WriteLine(record1.ModifiedTime);
        ZCRMUser CreatedBy = record1.CreatedBy;
        if(CreatedBy != null)
        {
            Console.WriteLine(CreatedBy.Id);
            Console.WriteLine(CreatedBy.FullName);
        }
        ZCRMUser ModifiedBy = record1.ModifiedBy;
        if (ModifiedBy != null)
        {
            Console.WriteLine(ModifiedBy.Id);
            Console.WriteLine(ModifiedBy.FullName);
        }
    }
}

In the request, "@updatecontact.json" contains the sample input.

Note

  • An error is thrown if the field value length is more than the maximum length defined for that field.

  • If an API is used inside a Function and the field value length exceeds the limit, then that function receives error response from the API. For ex: If the max length for a "Text field" is defined as 10, then value given for it in API cannot be "12345678901", as it has 11 characters.

  • Duplicates are checked for every insert record API call based on unique fields.

  • A maximum of 100 records can be inserted per API call.

  • You must use only Field API names in the input. You can obtain the field API names from

  • $approved key is used to set the records to be created in approval mode. It is mostly used for leads and contacts procured from webforms.

  • The trigger input can be workflow or approval. If the trigger is not mentioned, the workflows and approvals related to the API will get executed. Enter the trigger value as [] to not execute the workflows.

  • Refer Response Structure for more details about the JSON keys, values, and their descriptions. You can also use the sample response of each module as the input when you insert or update a record in that corresponding module.

Sample Input

Copied{
  "data": [
    {
      "id": "554023000000527002",
      "Mailing_State":"Baltimore"
    },
    {
      "id": "554023000000527003",
      "Mailing_State":"Baltimore"
    }
  ],
  "trigger": [
    "approval"
  ]
}

Possible Errors

  • INVALID_MODULEHTTP 400

    The module name given seems to be invalid
    Resolution: You have specified an invalid module name or there is no tab permission, or the module could have been removed from the available modules. Specify a valid module API name.

Sample Response

Copied{
  "data": [
    {
      "code": "SUCCESS",
      "details": {
        "Modified_Time": "2019-05-02T11:17:33+05:30",
        "Modified_By": {
          "name": "Patricia Boyle",
          "id": "554023000000235011"
        },
        "Created_Time": "2019-05-02T11:17:33+05:30",
        "id": "554023000000527002",
        "Created_By": {
          "name": "Patricia Boyle",
          "id": "554023000000235011"
        }
      },
      "message": "record updated",
      "status": "success"
    },
    {
      "code": "SUCCESS",
      "details": {
        "Modified_Time": "2019-05-02T11:17:33+05:30",
        "Modified_By": {
          "name": "Patricia Boyle",
          "id": "554023000000235011"
        },
        "Created_Time": "2019-05-02T11:17:33+05:30",
        "id": "554023000000527003",
        "Created_By": {
          "name": "Patricia Boyle",
          "id": "554023000000235011"
        }
      },
      "message": "record updated",
      "status": "success"
    }
  ]
}