Copiedcurl "https://www.zohoapis.com/crm/v2/Leads"
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-d "@newlead.json"
-X POST
Copied
String moduleAPIName = "Leads";
RecordOperations recordOperations = new RecordOperations();
BodyWrapper bodyWrapper = new BodyWrapper();
List < com.zoho.crm.api.record.Record > records = new ArrayList < com.zoho.crm.api.record.Record > ();
com.zoho.crm.api.record.Record record1 = new com.zoho.crm.api.record.Record();
record1.addFieldValue(Field.Leads.LAST_NAME, "Last Name");
List < FileDetails > fileDetails = new ArrayList < FileDetails > ();
FileDetails fileDetail1 = new FileDetails();
fileDetail1.setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c32537b7c2400dadca8ff55f620c65357da");
fileDetails.add(fileDetail1);
FileDetails fileDetail2 = new FileDetails();
fileDetail2.setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c32e0063e7321b5b4ca878a934519e6cdb2");
fileDetails.add(fileDetail2);
FileDetails fileDetail3 = new FileDetails();
fileDetail3.setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c323daf4780bfe0058133556f155795981f");
fileDetails.add(fileDetail3);
record1.addKeyValue("File_Upload", fileDetails);
List < Tag > tagList = new ArrayList < Tag > ();
Tag tag = new Tag();
tag.setName("Testtask");
tagList.add(tag);
record1.setTag(tagList);
records.add(record1);
bodyWrapper.setData(records);
List < String > trigger = new ArrayList < String > ();
trigger.add("approval");
trigger.add("workflow");
trigger.add("blueprint");
bodyWrapper.setTrigger(trigger);
HeaderMap headerInstance = new HeaderMap();
APIResponse < ActionHandler > response = recordOperations.createRecords(moduleAPIName, bodyWrapper, headerInstance);
Copiedimport javax.net.ssl.SSLContext;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;
public class InsertRecordsAPI
{
@SuppressWarnings("deprecation")
public static void main(String[] args)
{
try
{
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
SSLContext sslContext = SSLContext.getDefault();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpclient = httpClientBuilder.setSSLSocketFactory(sslConnectionSocketFactory).build();
URIBuilder uriBuilder = new URIBuilder("https://www.zohoapis.com/crm/v2/Leads");
HttpUriRequest requestObj = new HttpPost(uriBuilder.build());
HttpEntityEnclosingRequestBase requestBase = (HttpEntityEnclosingRequestBase) requestObj;
JSONObject requestBody = new JSONObject();
JSONArray recordArray = new JSONArray();
JSONObject recordObject = new JSONObject();
recordObject.put("Company", "Zylker");
recordObject.put("Last_Name", "Daly");
recordObject.put("First_Name", "Paul");
recordObject.put("Email", "p.daly@zylker.com");
recordObject.put("State", "Texas");
recordArray.put(recordObject);
recordObject = new JSONObject();
recordObject.put("Company", "Villa Margarita");
recordObject.put("Last_Name", "Dolan");
recordObject.put("First_Name", "Brian");
recordObject.put("Email", "brian@villa.com");
recordObject.put("State", "Texas");
recordArray.put(recordObject);
requestBody.put("data", recordArray);
JSONArray trigger = new JSONArray();
trigger.put("approval");
trigger.put("workflow");
trigger.put("blueprint");
requestBody.put("trigger", trigger);
requestBase.setEntity(new StringEntity(requestBody.toString(), HTTP.UTF_8));
requestObj.addHeader("Authorization", "Zoho-oauthtoken 1000.xxxxxxx.xxxxxxx");
HttpResponse response = httpclient.execute(requestObj);
HttpEntity responseEntity = response.getEntity();
System.out.println("HTTP Status Code : " + response.getStatusLine().getStatusCode());
if(responseEntity != null)
{
Object responseObject = EntityUtils.toString(responseEntity);
String responseString = responseObject.toString();
System.out.println(responseString);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
Copied
$recordOperations = new RecordOperations();
$bodyWrapper = new BodyWrapper();
$records = array();
$recordClass = 'com\zoho\crm\api\record\Record';
$record1 = new $recordClass();
$field = new Field("");
$record1->addFieldValue(Leads::LastName(), "FROm PHP");
$record1->addFieldValue(Accounts::AccountName(), "Account_Name");
record1->addKeyValue("Date_1", new \DateTime('2021-03-08'));
$record1->addKeyValue("Date_Time_2", date_create("2020-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get())));
$startdatetime = date_create("2020-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$record1->addFieldValue(Events::StartDateTime(), $startdatetime);
$record1->addFieldValue(Events::EventTitle(), "From PHP");
$enddatetime = date_create("2020-07-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$record1->addFieldValue(Events::EndDateTime(), $enddatetime);
$tagList = array();
$tag = new Tag();
$tag->setName("Testtask");
array_push($tagList, $tag);
$record1->setTag($tagList);
$bodyWrapper->setData($records);
$trigger = array("approval", "workflow", "blueprint");
$bodyWrapper->setTrigger($trigger);
$headerInstance = new HeaderMap();
$response = $recordOperations->createRecords($moduleAPIName,$bodyWrapper,$headerInstance);
Copied<?php
class InsertRecords
{
public function execute(){
$curl_pointer = curl_init();
$curl_options = array();
$url = "https://www.zohoapis.com/crm/v2/Leads";
$curl_options[CURLOPT_URL] =$url;
$curl_options[CURLOPT_RETURNTRANSFER] = true;
$curl_options[CURLOPT_HEADER] = 1;
$curl_options[CURLOPT_CUSTOMREQUEST] = "POST";
$requestBody = array();
$recordArray = array();
$recordObject = array();
$recordObject["Company"]="FieldAPIValue";
$recordObject["Last_Name"]="347706107420006";
$recordObject["First_Name"]="34770617420006";
$recordObject["State"]="FieldAPIValue";
$recordArray[] = $recordObject;
$requestBody["data"] =$recordArray;
$curl_options[CURLOPT_POSTFIELDS]= json_encode($requestBody);
$headersArray = array();
$headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " . "1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf";
$curl_options[CURLOPT_HTTPHEADER]=$headersArray;
curl_setopt_array($curl_pointer, $curl_options);
$result = curl_exec($curl_pointer);
$responseInfo = curl_getinfo($curl_pointer);
curl_close($curl_pointer);
list ($headers, $content) = explode("\r\n\r\n", $result, 2);
if(strpos($headers," 100 Continue")!==false){
list( $headers, $content) = explode( "\r\n\r\n", $content , 2);
}
$headerArray = (explode("\r\n", $headers, 50));
$headerMap = array();
foreach ($headerArray as $key) {
if (strpos($key, ":") != false) {
$firstHalf = substr($key, 0, strpos($key, ":"));
$secondHalf = substr($key, strpos($key, ":") + 1);
$headerMap[$firstHalf] = trim($secondHalf);
}
}
$jsonResponse = json_decode($content, true);
if ($jsonResponse == null && $responseInfo['http_code'] != 204) {
list ($headers, $content) = explode("\r\n\r\n", $content, 2);
$jsonResponse = json_decode($content, true);
}
var_dump($headerMap);
var_dump($jsonResponse);
var_dump($responseInfo['http_code']);
}
}
(new InsertRecords())->execute();
Copied
RecordOperations recordOperations = new RecordOperations();
BodyWrapper bodyWrapper = new BodyWrapper();
List<Com.Zoho.Crm.API.Record.Record> records = new List<Com.Zoho.Crm.API.Record.Record>();
Com.Zoho.Crm.API.Record.Record record1 = new Com.Zoho.Crm.API.Record.Record();
record1.AddFieldValue(Leads.CITY, "City");
record1.AddFieldValue(Leads.LAST_NAME, "Last Name");
record1.AddFieldValue(Leads.FIRST_NAME, "First Name");
record1.AddFieldValue(Leads.COMPANY, "KKRNP");
record1.AddKeyValue("Custom_field", "Value");
record1.AddKeyValue("Custom_field_2", "value");
record1.AddKeyValue("Date_Time_2", new DateTimeOffset(new DateTime(2020, 05, 15, 12, 0, 0, DateTimeKind.Local)));
record1.AddKeyValue("Date_1", new DateTime(2021, 1, 13).Date);
record1.AddKeyValue("Subject", "AutomatedSDK");
List<FileDetails> fileDetails = new List<FileDetails>();
FileDetails fileDetail1 = new FileDetails();
fileDetail1.FileId = "ae9c7cefa418aec1d6a5cc2d9ab35c32537b7c2400dadca8ff55f620c65357da";
fileDetails.Add(fileDetail1);
FileDetails fileDetail2 = new FileDetails();
fileDetail2.FileId = "ae9c7cefa418aec1d6a5cc2d9ab35c32e0063e7321b5b4ca878a934519e6cdb2";
fileDetails.Add(fileDetail2);
FileDetails fileDetail3 = new FileDetails();
fileDetail3.FileId = "ae9c7cefa418aec1d6a5cc2d9ab35c323daf4780bfe0058133556f155795981f";
fileDetails.Add(fileDetail3);
record1.AddKeyValue("File_Upload", fileDetails);
record1.AddFieldValue(Products.PRODUCT_NAME, "Product_Name");
Com.Zoho.Crm.API.Record.Record vendorName = new Com.Zoho.Crm.API.Record.Record();
vendorName.AddFieldValue(Products.ID, 3477061000004996051);
record1.AddFieldValue(Products.VENDOR_NAME, vendorName);
record1.AddFieldValue(Products.PRODUCT_CATEGORY, new Choice<string>("Software"));
record1.AddFieldValue(Products.PRODUCT_ACTIVE, true);
record1.AddFieldValue(Products.SALES_START_DATE, new DateTime(2020, 10, 12));
record1.AddFieldValue(Products.SALES_END_DATE, new DateTime(2020, 12, 12));
record1.AddFieldValue(Products.TAXABLE, true);
List<Choice<string>> taxes = new List<Choice<string>>();
taxes.Add(new Choice<string>("MyTax22"));
taxes.Add(new Choice<string>("Sales Tax"));
taxes.Add(new Choice<string>("MyTax11"));
taxes.Add(new Choice<string>("Vat"));
taxes.Add(new Choice<string>("MyTax23"));
record1.AddFieldValue(Products.TAX, taxes);
Com.Zoho.Crm.API.Record.Record dealName = new Com.Zoho.Crm.API.Record.Record();
dealName.AddFieldValue(Deals.ID, 3477061000004995070);
record1.AddFieldValue(Sales_Orders.DEAL_NAME, dealName);
Com.Zoho.Crm.API.Record.Record contactName = new Com.Zoho.Crm.API.Record.Record();
contactName.AddFieldValue(Contacts.ID, 3477061000004977055);
record1.AddFieldValue(Purchase_Orders.CONTACT_NAME, contactName);
Com.Zoho.Crm.API.Record.Record accountName = new Com.Zoho.Crm.API.Record.Record();
accountName.AddKeyValue("name", "automatedAccount");
record1.AddFieldValue(Quotes.ACCOUNT_NAME, accountName);
List<InventoryLineItems> inventoryLineItemList = new List<InventoryLineItems>();
InventoryLineItems inventoryLineItem = new InventoryLineItems();
LineItemProduct lineItemProduct = new LineItemProduct();
lineItemProduct.Id = 3477061000006611017;
inventoryLineItem.Product = lineItemProduct;
inventoryLineItem.Quantity = 1.5;
inventoryLineItem.ProductDescription = "productDescription";
inventoryLineItem.ListPrice = 10.0;
inventoryLineItem.Discount = "5.0";
inventoryLineItem.Discount = "5.25%";
List<LineTax> productLineTaxes = new List<LineTax>();
LineTax productLineTax = new LineTax();
productLineTax.Name = "MyTax22";
productLineTax.Percentage = 20.0;
productLineTaxes.Add(productLineTax);
inventoryLineItem.LineTax = productLineTaxes;
inventoryLineItemList.Add(inventoryLineItem);
record1.AddKeyValue("Product_Details", inventoryLineItemList);
List<LineTax> lineTaxes = new List<LineTax>();
LineTax lineTax = new LineTax();
lineTax.Name = "MyTax22";
lineTax.Percentage = 20.0;
lineTaxes.Add(lineTax);
record1.AddKeyValue("$line_tax", lineTaxes);
record1.AddFieldValue(Tasks.DESCRIPTION, "Test Task");
record1.AddKeyValue("Currency", new Choice<string>("INR"));
RemindAt remindAt = new RemindAt();
remindAt.Alarm = "FREQ=NONE;ACTION=EMAILANDPOPUP;TRIGGER=DATE-TIME:2020-09-03T12:30:00+05:30";
record1.AddFieldValue(Tasks.REMIND_AT, remindAt);
Com.Zoho.Crm.API.Record.Record whoId = new Com.Zoho.Crm.API.Record.Record();
whoId.Id = 3477061000004977055;
record1.AddFieldValue(Tasks.WHO_ID, whoId);
record1.AddFieldValue(Tasks.STATUS, new Choice<string>("Waiting for input"));
record1.AddFieldValue(Tasks.DUE_DATE, new DateTime(2021, 1, 13));
record1.AddFieldValue(Tasks.PRIORITY, new Choice<string>("High"));
record1.AddKeyValue("$se_module", "Accounts");
record1.AddFieldValue(Tasks.SUBJECT, "Email1");
Com.Zoho.Crm.API.Record.Record whatId = new Com.Zoho.Crm.API.Record.Record();
whatId.Id = 3477061000000207118;
record1.AddFieldValue(Tasks.WHAT_ID, whatId);
RecurringActivity recurringActivity = new RecurringActivity();
recurringActivity.Rrule = "FREQ=DAILY;INTERVAL=10;UNTIL=2020-08-14;DTSTART=2020-07-03";
record1.AddFieldValue(Events.RECURRING_ACTIVITY, recurringActivity);
record1.AddFieldValue(Events.DESCRIPTION, "Test Events");
DateTimeOffset startDateTime = new DateTimeOffset(new DateTime(2020, 05, 15, 12, 0, 0, DateTimeKind.Local));
record1.AddFieldValue(Events.START_DATETIME, startDateTime);
List<Participants> participants = new List<Participants>();
Participants participant1 = new Participants();
participant1.Participant = "raja@gmail.com";
participant1.Type = "email";
participant1.Id = 3477061000005902017;
participants.Add(participant1);
Participants participant2 = new Participants();
participant2.AddKeyValue("participant", "3477061000007078158");
participant2.AddKeyValue("type", "lead");
participants.Add(participant2);
record1.AddFieldValue(Events.PARTICIPANTS, participants);
record1.AddKeyValue("$send_notification", true);
record1.AddFieldValue(Events.EVENT_TITLE, "New Automated Event");
DateTimeOffset enddatetime = new DateTimeOffset(new DateTime(2020, 09, 15, 12, 0, 0, DateTimeKind.Local));
record1.AddFieldValue(Events.END_DATETIME, enddatetime);
DateTimeOffset remindAt1 = new DateTimeOffset(new DateTime(2020, 08, 15, 12, 0, 0, DateTimeKind.Local));
record1.AddFieldValue(Events.REMIND_AT, remindAt1);
record1.AddFieldValue(Events.CHECK_IN_STATUS, "PLANNED");
record1.AddKeyValue("$se_module", "Leads");
Com.Zoho.Crm.API.Record.Record whatId1 = new Com.Zoho.Crm.API.Record.Record();
whatId1.Id = 3477061000004381002;
record1.AddFieldValue(Events.WHAT_ID, whatId1);
List<PricingDetails> pricingDetails = new List<PricingDetails>();
PricingDetails pricingDetail1 = new PricingDetails();
pricingDetail1.FromRange = 1.0;
pricingDetail1.ToRange = 5.0;
pricingDetail1.Discount = 2.0;
pricingDetails.Add(pricingDetail1);
PricingDetails pricingDetail2 = new PricingDetails();
pricingDetail2.AddKeyValue("from_range", 6.0);
pricingDetail2.AddKeyValue("to_range", 11.0);
pricingDetail2.AddKeyValue("discount", 3.0);
pricingDetails.Add(pricingDetail2);
record1.AddFieldValue(Price_Books.PRICING_DETAILS, pricingDetails);
record1.AddKeyValue("Email", "raja.k126@zoho.com");
record1.AddFieldValue(Price_Books.DESCRIPTION, "TEST");
record1.AddFieldValue(Price_Books.PRICE_BOOK_NAME, "book_name");
record1.AddFieldValue(Price_Books.PRICING_MODEL, new Choice<string>("Flat1"));
List<Tag> tagList = new List<Tag>();
Tag tag = new Tag();
tag.Name = "Testtask";
tagList.Add(tag);
record1.Tag = tagList;
records.Add(record1);
bodyWrapper.Data = records;
List<string> trigger = new List<string>();
trigger.Add("approval");
trigger.Add("workflow");
trigger.Add("blueprint");
bodyWrapper.Trigger = trigger;
HeaderMap headerInstance = new HeaderMap();
APIResponse<ActionHandler> response = recordOperations.CreateRecords(moduleAPIName, bodyWrapper,headerInstance);
Copiedusing System;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json.Linq;
namespace Com.Zoho.Crm.API.Sample.RestAPI.Records
{
public class InsertRecordsAPI
{
public static void InsertRecords()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.zohoapis.com/crm/v2/Leads");
request.Method = "POST";
request.Headers["Authorization"] = "Zoho-oauthtoken 1000.abfeXXXXXXXXXXX2asw.XXXXXXXXXXXXXXXXXXsdc2";
JObject requestBody = new JObject();
JArray recordArray = new JArray();
JObject recordObject = new JObject();
recordObject.Add("Company", "Zylker");
recordObject.Add("Last_Name", "Daly");
recordObject.Add("First_Name", "Paul");
recordObject.Add("Email", "p.daly@zylker.com");
recordObject.Add("State", "Texas");
recordArray.Add(recordObject);
recordObject = new JObject();
recordObject.Add("Company", "Villa Margarita");
recordObject.Add("Last_Name", "Dolan");
recordObject.Add("First_Name", "Brian");
recordObject.Add("Email", "brian@villa.com");
recordObject.Add("State", "Texas");
recordArray.Add(recordObject);
requestBody.Add("data", recordArray);
JArray trigger = new JArray();
trigger.Add("approval");
trigger.Add("workflow");
trigger.Add("blueprint");
requestBody.Add("trigger", trigger);
string dataString = requestBody.ToString();
var data = Encoding.UTF8.GetBytes(dataString);
int dataLength = data.Length;
request.ContentLength = dataLength;
using (var writer = request.GetRequestStream())
{
writer.Write(data, 0, dataLength);
}
request.KeepAlive = true;
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
if (e.Response == null) { throw; }
response = (HttpWebResponse)e.Response;
}
HttpWebResponse responseEntity = response;
Console.WriteLine("HTTP Status Code : " + (int)response.StatusCode);
string responsestring = new StreamReader(responseEntity.GetResponseStream()).ReadToEnd();
responseEntity.Close();
Console.WriteLine(responsestring);
}
}
}
Copied
record_operations = RecordOperations()
request = BodyWrapper()
records_list = []
record = ZCRMRecord()
"""
Call add_field_value method that takes two arguments
Import the zcrmsdk.src.com.zoho.crm.api.record.field file
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.add_field_value(Field.Leads.last_name(), 'Python SDK')
record.add_field_value(Field.Leads.first_name(), 'New')
record.add_field_value(Field.Leads.company(), 'Zoho')
record.add_field_value(Field.Leads.city(), 'City')
record.add_field_value(Field.Leads.salutation(), Choice('Prof.'))
record.add_key_value('Multi_Select_1', [Choice('Test2'), Choice('Test1')])
record.add_key_value('External', 'Test1')
"""
Call add_key_value method that takes two arguments
1 -> A string that is the Field's API Name
2 -> Value
"""
record.add_key_value('Custom_field', 'Value')
record.add_key_value('Custom_field_2', 12)
record.add_key_value('Date', date(2020, 4, 9))
record.add_key_value('Discounted', 23.34)
tax_name = [Choice('Vat'), Choice('Sales Tax')]
record.add_key_value("Tax", tax_name)
record.add_key_value("Product_Name", "AutomatedSDK")
file_details = []
file_detail = FileDetails()
file_detail.set_file_id('479f0f5eebf0fb982f99e3832b35d23e29f67c2868ee4c789f22579895383c8')
file_details.append(file_detail)
record.add_key_value('File_Upload', file_details)
"""
Following methods are being used only by Inventory modules
"""
deal_name = ZCRMRecord()
deal_name.add_field_value(Field.Deals.id(), 3477061000011067033)
record.add_field_value(Field.Sales_Orders.deal_name(), deal_name)
contact_name = ZCRMRecord()
contact_name.add_field_value(Field.Contacts.id(), 3477061000010346007)
record.add_field_value(Field.Sales_Orders.contact_name(), contact_name)
account_name = ZCRMRecord()
account_name.add_field_value(Field.Accounts.id(), 3477061000011067025)
record.add_field_value(Field.Sales_Orders.account_name(), account_name)
record.add_key_value("Discount", 10.5)
inventory_line_item_list = []
inventory_line_item = InventoryLineItems()
line_item_product = LineItemProduct()
line_item_product.add_key_value("Products_External", "TestExternalLead121")
inventory_line_item.set_product(line_item_product)
inventory_line_item.set_quantity(3.0)
inventory_line_item.set_product_description('productDescription')
inventory_line_item.set_list_price(10.0)
inventory_line_item.set_discount('5.90')
product_line_taxes = []
product_line_tax = LineTax()
product_line_tax.set_name('Tax1')
product_line_tax.set_percentage(12.0)
product_line_taxes.append(product_line_tax)
inventory_line_item_list.append(inventory_line_item)
record.add_key_value('Product_Details', inventory_line_item_list)
record.add_field_value(Field.Quotes.subject(), "Python- testing")
line_taxes = []
line_tax = LineTax()
line_tax.set_name('Total-Tax')
line_tax.set_percentage(5.0)
line_taxes.append(line_tax)
record.add_key_value("$line_tax", line_taxes)
vendor_name = ZCRMRecord()
vendor_name.set_id(1234)
record.add_field_value(Field.Purchase_Orders.vendor_name(), vendor_name)
"""
End Inventory
"""
"""
Following methods are being used only by Activity modules
"""
record.add_field_value(Field.Tasks.description(), "New Task")
record.add_key_value('Currency', Choice('INR'))
remind_at = RemindAt()
remind_at.set_alarm("FREQ=NONE;ACTION=POPUP;TRIGGER=DATE-TIME:2021-01-18T12:45:00+05:30")
record.add_field_value(Field.Tasks.remind_at(), remind_at)
record.add_field_value(Field.Tasks.subject(), "Python - testing")
record.add_field_value(Field.Calls.reminder(), Choice("5 mins"))
record.add_field_value(Field.Calls.call_type(), Choice("Outbound"))
record.add_field_value(Field.Calls.call_start_time(), datetime(2020,12,1,1,1,1))
who_id = ZCRMRecord()
who_id.set_id(3477061000010346007)
record.add_field_value(Field.Tasks.who_id(), who_id)
record.add_field_value(Field.Tasks.status(), Choice('Waiting for Input'))
record.add_field_value(Field.Tasks.due_date(), date(2020, 10, 10))
record.add_field_value(Field.Tasks.priority(), Choice('High'))
what_id = ZCRMRecord()
what_id.set_id(3477061000011067025)
record.add_field_value(Field.Tasks.what_id(), what_id)
record.add_key_value("$se_module", "Accounts")
recurring_activity = RecurringActivity()
recurring_activity.set_rrule('FREQ=DAILY;INTERVAL=10;UNTIL=2020-08-14;DTSTART=2020-07-03')
record.add_field_value(Field.Events.recurring_activity(), recurring_activity)
record.add_field_value(Field.Events.description(), "My Event")
start_date_time = datetime.fromisoformat('2020-07-03T12:30:00+05:30')
record.add_field_value(Field.Events.start_datetime(), start_date_time)
participants_list = []
participant = Participants()
participant.set_participant('test@gmail.com')
participant.set_type('email')
participants_list.append(participant)
participant = Participants()
participant.set_participant('3477061000010346007')
participant.set_type('contact')
participants_list.append(participant)
record.add_field_value(Field.Events.participants(), participants_list)
record.add_key_value("$send_notification", True)
record.add_field_value(Field.Events.event_title(), "New Automated Event")
end_date_time = datetime(2020, 9, 3, 10, 10, 10)
record.add_field_value(Field.Events.end_datetime(), end_date_time)
remind_at_value = datetime(2020, 7, 3, 8, 10, 10)
record.add_field_value(Field.Events.remind_at(), remind_at_value)
record.add_field_value(Field.Events.check_in_status(), 'PLANNED')
what_id = ZCRMRecord()
what_id.set_id(3477061000011218001)
record.add_field_value(Field.Events.what_id(), what_id)
record.add_key_value("$se_module", "Leads")
"""
End Activity
"""
"""
Following methods are being used only by Price_Books module
"""
pricing_details_list = []
pricing_detail = PricingDetails()
pricing_detail.set_from_range(1.0)
pricing_detail.set_to_range(5.0)
pricing_detail.set_discount(2.0)
pricing_details_list.append(pricing_detail)
pricing_detail = PricingDetails()
pricing_detail.add_key_value('from_range', 6.0)
pricing_detail.add_key_value('to_range', 11.0)
pricing_detail.add_key_value('discount', 3.0)
pricing_details_list.append(pricing_detail)
record.add_field_value(Field.Price_Books.pricing_details(), pricing_details_list)
record.add_key_value("Email", "abc@zoho.com")
record.add_field_value(Field.Price_Books.description(), "My Price Book")
record.add_field_value(Field.Price_Books.price_book_name(), 'book_name')
record.add_field_value(Field.Price_Books.pricing_model(), Choice('Flat'))
"""
End of Price_Books
"""
data_consent = Consent()
data_consent.set_consent_remarks("Approved.")\
data_consent.set_consent_through('Email')
data_consent.set_contact_through_email(True)
data_consent.set_contact_through_social(False)
record.add_key_value('Data_Processing_Basis_Details', data_consent)
tags_list = []
tag = Tag()
tag.set_name("My Record")
tags_list.append(tag)
records_list.append(record)
request.set_data(records_list)
trigger = ["approval", "workflow", "blueprint"]
request.set_trigger(trigger)
lar_id = '3409643000002157065'
request.set_lar_id(lar_id)
process = ["review_process"]
request.set_process(process)
header_instance = HeaderMap()
header_instance.add(CreateRecordsHeader.x_external, "Quotes.Product_Details.product.Products_External")
response = record_operations.create_records(module_api_name, request, header_instance)
Copieddef insert_records():
import requests
import json
url = 'https://www.zohoapis.com/crm/v2/Leads'
headers = {
'Authorization': 'Zoho-oauthtoken 1000.04be928e4a96XXXXXXXXXXXXX68.0b9eXXXXXXXXXXXX60396e268',
}
request_body = dict()
record_list = list()
record_object_1 = {
'Company': 'Zylker',
'Email': 'p.daly@zylker.com',
'Last_Name': 'Daly',
'First_Name': 'Paul',
'Lead_Status': 'Contacted',
}
record_object_2 = {
'Last_Name': 'Dolan',
'First_Name': 'Brian',
'Email': 'brian@villa.com',
'Company': 'Villa Margarita'
}
record_list.append(record_object_1)
record_list.append(record_object_2)
request_body['data'] = record_list
trigger = [
'approval',
'workflow',
'blueprint'
]
request_body['trigger'] = trigger
response = requests.post(url=url, headers=headers, data=json.dumps(request_body).encode('utf-8'))
if response is not None:
print("HTTP Status Code : " + str(response.status_code))
print(response.json())
insert_records()
Copied//Get instance of RecordOperations Class
let recordOperations = new RecordOperations();
//Get instance of BodyWrapper Class that will contain the request body
let request = new BodyWrapper();
//Array to hold Record instances
let recordsArray = [];
//Get instance of Record Class
let record = new Record();
/* Value to Record's fields can be provided in any of the following ways */
/*
* Call addFieldValue method that takes two arguments
* Import the "zcrmsdk/core/com/zoho/crm/api/record/field" file
* 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(Field.Leads.LAST_NAME, "Node JS SDK");
record.addFieldValue(Field.Leads.FIRST_NAME, "Node");
record.addFieldValue(Field.Leads.COMPANY, "ZCRM");
record.addFieldValue(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 FileDetails();
fileDetail.setFileId("479f0f5eebf0fb982f99e3832b35d23e29f67c2868ee4c789f22579895383c8");
fileDetails.push(fileDetail);
fileDetail = new FileDetails();
fileDetail.setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c32e0063e7321b5b4ca878a934519e6cdb2");
fileDetails.push(fileDetail);
fileDetail = new FileDetails();
fileDetail.setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c323daf4780bfe0058133556f155795981f");
fileDetails.push(fileDetail);
record.addKeyValue("File_Upload_1", fileDetails);
//Used when GDPR is enabled
let dataConsent = new 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 Record();
dealName.addFieldValue(Field.Deals.ID, "3409643000002000001");
record.addFieldValue(Field.Sales_Orders.DEAL_NAME, dealName);
let contactName = new Record();
contactName.addFieldValue(Field.Contacts.ID, "3409643000001074007");
contactName.addFieldValue(Field.Sales_Orders.CONTACT_NAME, contactName);
let accountName = new Record();
accountName.addFieldValue(Field.Accounts.ID, "3409643000000692007");
record.addFieldValue(Field.Sales_Orders.ACCOUNT_NAME, accountName);
record.addKeyValue("Discount", 10.5);
let inventoryLineItemArray = [];
let inventoryLineItem = new InventoryLineItems();
let lineItemProduct = new LineItemProduct();
lineItemProduct.setId(3409643000000986033n);
inventoryLineItem.setProduct(lineItemProduct);
inventoryLineItem.setQuantity(3);
inventoryLineItem.setProductDescription("productDescription");
inventoryLineItem.setListPrice(10.0);
inventoryLineItem.setDiscount("5.90");
let productLineTaxes = [];
let productLineTax = new LineTax();
productLineTax.setName("Tax1");
productLineTax.setPercentage(20.0);
productLineTaxes.push(productLineTax);
inventoryLineItem.setLineTax(productLineTaxes);
inventoryLineItemArray.push(inventoryLineItem);
record.addKeyValue("Product_Details", inventoryLineItemArray);
let lineTaxes = [];
let lineTax = new LineTax();
lineTax.setName("Tax1");
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(Field.Tasks.DESCRIPTION, "New Task");
record.addKeyValue("Currency", new Choice("INR"));
let remindAt = new RemindAt();
remindAt.setAlarm("FREQ=NONE;ACTION=EMAILANDPOPUP;TRIGGER=DATE-TIME:2020-07-03T12:30:00+05:30");
record.addFieldValue(Field.Tasks.REMIND_AT, remindAt);
let whoId = new Record();
whoId.setId(3409643000000836001n);
record.addFieldValue(Field.Tasks.WHO_ID, whoId);
record.addFieldValue(Field.Tasks.STATUS, new Choice("Waiting for Input"));
record.addFieldValue(Field.Tasks.DUE_DATE, new Date(2020,10,10));
record.addFieldValue(Field.Tasks.PRIORITY, new Choice("High"));
let whatId = new Record();
whatId.setId(3409643000000692007n);
record.addFieldValue(Field.Tasks.WHAT_ID, whatId);
record.addKeyValue("$se_module", "Accounts");
/** Recurring Activity can be provided in any activity module*/
let recurringActivity = new RecurringActivity();
recurringActivity.setRrule("FREQ=DAILY;INTERVAL=10;UNTIL=2020-08-14;DTSTART=2020-07-03");
record.addFieldValue(Field.Events.RECURRING_ACTIVITY, recurringActivity);
record.addFieldValue(Field.Events.DESCRIPTION, "My Event");
let startDateTime = new Date('October 15, 2020 05:35:32');
record.addFieldValue(Field.Events.START_DATETIME, startDateTime);
let participantsArray = [];
let participant = new Participant();
participant.setParticipant("test@gmail.com");
participant.setType("email");
participantsArray.push(participant);
participant = new Participant();
participant.setParticipant("3409643000000836001");
participant.setType("Contact");
participantsArray.push(participant);
record.addFieldValue(Field.Events.PARTICIPANTS, participantsArray);
record.addKeyValue("$send_notification", true);
record.addFieldValue(Field.Events.EVENT_TITLE, "New Automated Event");
let endDateTime = new Date('November 15, 2020 05:35:32');
record.addFieldValue(Field.Events.END_DATETIME, endDateTime);
let remindAt1 = new Date('October 15, 2020 04:35:32');
record.addFieldValue(Field.Events.REMIND_AT, remindAt1);
record.addFieldValue(Field.Events.CHECK_IN_STATUS, "PLANNED");
whatId = new Record();
whatId.setId(3409643000002157023n);
record.addFieldValue(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 PricingDetails();
pricingDetail.setFromRange(1.0);
pricingDetail.setToRange(5.0);
pricingDetail.setDiscount(2.0);
pricingDetailsArray.push(pricingDetail);
pricingDetail = new PricingDetails();
pricingDetail.addKeyValue("from_range", 6.0);
pricingDetail.addKeyValue("to_range", 11.0);
pricingDetail.addKeyValue("discount", 3.0);
pricingDetailsArray.push(pricingDetail);
record.addFieldValue(Field.Price_Books.PRICING_DETAILS, pricingDetailsArray);
record.addKeyValue("Email", "z1@zoho.com");
record.addFieldValue(Field.Price_Books.DESCRIPTION, "TEST");
record.addFieldValue(Field.Price_Books.PRICE_BOOK_NAME, "book_name");
record.addFieldValue(Field.Price_Books.PRICING_MODEL, new Choice("Flat"));
/** End of Price_Books */
let tagsArray = [];
let tag = new Tag();
tag.setName("Testtask");
tagsArray.push(tag);
//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 = "3409643000002157065";
//Set the larId
request.setLarId(larId);
let process = ["review_process"];
//Set the array containing the process to be run
request.setProcess(process);
//Get instance of HeaderMap Class
let headerInstance = new HeaderMap();
//Call createRecords method that takes BodyWrapper instance and moduleAPIName as parameters
let response = await recordOperations.createRecords(moduleAPIName, request,headerInstance);
Copiedasync function insertRecords() {
const got = require("got");
let url = 'https://www.zohoapis.com/crm/v2/Leads'
let headers = {
Authorization : "Zoho-oauthtoken 1000.354df3680XXXXXXXXXXXXX3.aae0efXXXXXXXXXXXXXXXXXX9"
}
let requestBody = {}
let recordArray = []
let recordObject1 = {
'Company': 'Zylker',
'Email': 'p.daly@zylker.com',
'Last_Name': 'Daly',
'First_Name': 'Paul',
'Lead_Status': 'Contacted',
}
let recordObject2 = {
'Last_Name': 'Dolan',
'First_Name': 'Brian',
'Email': 'brian@villa.com',
'Company': 'Villa Margarita'
}
recordArray.push(recordObject1)
recordArray.push(recordObject2)
requestBody['data'] = recordArray
let trigger = ['approval', 'workflow', 'blueprint']
requestBody['trigger'] = trigger
let requestDetails = {
method : "POST",
headers : headers,
body : JSON.stringify(requestBody),
encoding: "utf8",
throwHttpErrors : false
};
let response = await got(url, requestDetails)
if(response != null) {
console.log(response.statusCode);
console.log(response.body);
}
}
insertRecords()
Copied
records = []
record = Record::Record.new
if module_api_name.downcase == 'Leads'.downcase
record.add_field_value(Record::Field::Leads.Last_name, 'asdad')
record.add_field_value(Record::Field::Leads.City, 'City')
record.add_field_value(Record::Field::Leads.First_name, 'First Name')
record.add_field_value(Record::Field::Leads.Company, 'KKRNP')
end
if module_api_name == 'Contacts'
file_details = []
file_detail = Record::FileDetails.new
file_detail.file_id = '479f0f5eebf0fb982f99e3832b35d23e29f67c2868ee4c789f22579895383c8'
file_details.push(file_detail)
record.add_key_value('File_Upload_1', file_details)
end
if %w[Quotes Sales_Orders Purchase_Orders Invoices].include? module_api_name
line_item_product = Record::LineItemProduct.new
line_item_product.id = 3_524_033_000_003_659_082
inventory_line_item = Record::InventoryLineItems.new
inventory_line_item.product = nil
inventory_line_item.list_price = 10.0
inventory_line_item.discount = '5.0'
inventory_line_item.quantity = 123.2
line_tax = Record::LineTax.new
line_tax.name = 'Tax1'
line_tax.percentage = 20.0
line_taxes = [line_tax]
inventory_line_item.line_tax = line_taxes
inventory_line_items = [inventory_line_item]
record.add_key_value('Product_Details', inventory_line_items)
record.add_key_value('Subject', 'asd')
end
if %w[Tasks Events Calls].include? module_api_name
remind_at = Record::RemindAt.new
remind_at.alarm = 'FREQ=NONE;ACTION=EMAILANDPOPUP;TRIGGER=DATE-TIME:2020-07-03T12:30:00+05:30'
who_id = Record::Record.new
who_id.id = 3_524_033_000_003_429_023
record.add_field_value(Record::Field::Tasks.Who_id, who_id)
participant_record = Record::Participants.new
participant_record.participant = 'asdasd@gmail.com'
participant_record.type = 'email'
record.add_field_value(Record::Field::Events.Event_title, 'New Automated Event')
endtime = DateTime.new(2019, 8, 10, 4, 11, 9, '+03:00')
record.add_field_value(Record::Field::Events.End_datetime, endtime)
starttime = DateTime.new(2019, 8, 10, 4, 10, 9, '+03:00')
record.add_field_value(Record::Field::Events.Start_datetime, starttime)
participants = [participant_record]
record.add_field_value(Record::Field::Events.Start_datetime, starttime)
recurring_activity = Record::RecurringActivity.new
recurring_activity.rrule = 'FREQ=DAILY;INTERVAL=10;UNTIL=2020-08-14;DTSTART=2020-07-03'
record.add_field_value(Record::Field::Events.Recurring_activity, recurring_activity)
end
if module_api_name == 'Price_Books'
pricing_detail_record = Record::PricingDetails.new
pricing_detail_record.from_range = 1.0
pricing_detail_record.to_range = 1.0
pricing_detail_record.discount = 1.0
pricing_detail_records = [pricing_detail_record]
record.add_key_value('Price_Book_Name', 'assd')
record.add_field_value(Record::Field::Price_Books.Pricing_details, pricing_detail_records)
record.add_field_value(Record::Field::Price_Books.Pricing_model, Util::Choice.new('Flat'))
end
records.push(record)
trigger = []
trigger.push('approval')
trigger.push('workflow')
trigger.push('blueprint')
body_wrapper = Record::BodyWrapper.new
body_wrapper.data = records
body_wrapper.lar_id = '213123131'
body_wrapper.trigger = trigger
process = ['review_process']
body_wrapper.process = process
rr = Record::RecordOperations.new
hm = HeaderMap.new
response = rr.create_records(module_api_name,body_wrapper,hm)
Copiedclass InsertRecords
def execute
url ="https://www.zohoapis.com/crm/v2/Leads"
url = URI(url)
req = Net::HTTP::Post.new(url.request_uri)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
headers={}
headers["Authorization"]="Zoho-oauthtoken 1000.354df3680XXXXXXXXXXXXX3.aae0efXXXXXXXXXXXXXXXXXX9"
headers&.each { |key, value| req.add_field(key, value) }
request_body = {};
record_array = [];
record_object = {};
record_object["FieldAPIName"] = "FieldAPIValue";
record_object["Company"]="FieldAPIValue";
record_object["Last_Name"]="3477061000007420006";
record_object["First_Name"]="3477061000007420006";
record_object["State"]="FieldAPIValue";
record_array = [record_object];
request_body["data"] =record_array;
request_json = request_body.to_json
req.body = request_json.to_s
response=http.request(req)
status_code = response.code.to_i
headers = response.each_header.to_h
print status_code
print headers
unless response.body.nil?
print response.body
end
end
end
InsertRecords.new.execute
Copied
let recordOperations = new ZCRM.Record.Operations();
let request = new ZCRM.Record.Model.BodyWrapper();
let recordsArray = [];
let record = new ZCRM.Record.Model.Record();
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");
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);
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);
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);
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");
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@gmail.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");
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@zoho.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"));
let tagsArray = [];
let tag = new ZCRM.Tag.Model.Tag();
tag.setName("Testtask");
tagsArray.push(tag);
record.setTag(tagsArray);
recordsArray.push(record);
request.setData(recordsArray);
let trigger = [];
trigger.push("approval");
trigger.push("workflow");
trigger.push("blueprint");
request.setTrigger(trigger);
let larId = "34096432157065";
request.setLarId(larId);
let process = ["review_process"];
request.setProcess(process);
let response = await recordOperations.createRecords(moduleAPIName, request);
Copiedvar listener = 0;
class InsertRecordsAPI {
async insertRecords() {
var url = "https://www.zohoapis.com/crm/v2/Leads"
var parameters = new Map()
var headers = new Map()
var token = {
clientId:"1000.NPY9M1V0XXXXXXXXXXXXXXXXXXXF7H",
redirectUrl:"http://127.0.0.1:5500/redirect.html",
scope:"ZohoCRM.users.ALL,ZohoCRM.bulk.read,ZohoCRM.modules.ALL,ZohoCRM.settings.ALL,Aaaserver.profile.Read,ZohoCRM.org.ALL,profile.userphoto.READ,ZohoFiles.files.ALL,ZohoCRM.bulk.ALL,ZohoCRM.settings.variable_groups.ALL"
}
var accesstoken = await new InsertRecordsAPI().getToken(token)
headers.set("Authorization", "Zoho-oauthtoken " + accesstoken)
var requestMethod = "POST"
var reqBody = {"data":[{"Last_Name":"Lead_changed","Email":"newcrmapi@zoho.com","Company":"abc","Lead_Status":"Contacted"},{"Last_Name":"New Lead","Email":"newlead@zoho.com","Company":"abc","Lead_Status":"Contacted"}],"trigger":["approval","workflow","blueprint"]}
var params = "";
parameters.forEach(function(value, key) {
if (parameters.has(key)) {
if (params) {
params = params + key + '=' + value + '&';
}
else {
params = key + '=' + value + '&';
}
}
});
var apiHeaders = {};
if(headers) {
headers.forEach(function(value, key) {
apiHeaders[key] = value;
});
}
if (params.length > 0){
url = url + '?' + params.substring(0, params.length - 1);
}
var requestObj = {
uri : url,
method : requestMethod,
headers : apiHeaders,
body : JSON.stringify(reqBody),
encoding: "utf8",
allowGetBody : true,
throwHttpErrors : false
};
var result = await new InsertRecordsAPI().makeAPICall(requestObj);
console.log(result.status)
console.log(result.response)
}
async getToken(token) {
if(listener == 0) {
window.addEventListener("storage", function(reponse) {
if(reponse.key === "access_token" && (reponse.oldValue != reponse.newValue || reponse.oldValue == null)){
location.reload();
}
if(reponse.key === "access_token"){
sessionStorage.removeItem("__auth_process");
}
}, false);
listener = 1;
if(sessionStorage.getItem("__auth_process")) {
sessionStorage.removeItem("__auth_process");
}
}
["granted_for_session", "access_token","expires_in","expires_in_sec","location","api_domain","state","__token_init","__auth_process"].forEach(function (k) {
var isKeyExists = localStorage.hasOwnProperty(k);
if(isKeyExists) {
sessionStorage.setItem(k, localStorage[k]);
}
localStorage.removeItem(k);
});
var valueInStore = sessionStorage.getItem("access_token");
var tokenInit = sessionStorage.getItem("__token_init");
if(tokenInit != null && valueInStore != null && Date.now() >= parseInt(tokenInit) + 59 * 60 * 1000){
valueInStore = null;
sessionStorage.removeItem("access_token");
}
var auth_process = sessionStorage.getItem("__auth_process");
if ((valueInStore == null && auth_process == null) || (valueInStore == 'undefined' && (auth_process == null || auth_process == "true"))) {
var accountsUrl = "https://accounts.zoho.com/oauth/v2/auth"
var clientId;
var scope;
var redirectUrl;
if(token != null) {
clientId = token.clientId;
scope = token.scope;
redirectUrl = token.redirectUrl;
}
var fullGrant = sessionStorage.getItem("full_grant");
var grantedForSession = sessionStorage.getItem("granted_for_session");
if(sessionStorage.getItem("__token_init") != null && ((fullGrant != null && "true" == full_grant) || (grantedForSession != null && "true" == grantedForSession))) {
accountsUrl += '/refresh';
}
if (clientId && scope) {
sessionStorage.setItem("__token_init", Date.now());
sessionStorage.removeItem("access_token");
sessionStorage.setItem("__auth_process", "true");
window.open(accountsUrl + "?" + "scope" + "=" + scope + "&"+ "client_id" +"=" + clientId + "&response_type=token&state=zohocrmclient&redirect_uri=" + redirectUrl);
["granted_for_session", "access_token","expires_in","expires_in_sec","location","api_domain","state","__token_init","__auth_process"].forEach(function (k) {
var isKeyExists = localStorage.hasOwnProperty(k);
if(isKeyExists){
sessionStorage.setItem(k, localStorage[k]);
}
localStorage.removeItem(k);
});
valueInStore = sessionStorage.getItem("access_token");
}
}
if(token != null && valueInStore != 'undefined'){
token.accessToken = valueInStore;
}
return token.accessToken;
}
async makeAPICall(requestDetails) {
return new Promise(function (resolve, reject) {
var body, xhr, i;
body = requestDetails.body || null;
xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open(requestDetails.method, requestDetails.uri, true);
for (i in requestDetails.headers) {
xhr.setRequestHeader(i, requestDetails.headers[i]);
}
xhr.send(body);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
resolve(xhr);
}
}
})
}
}
CopiedSyntax:
zoho.crm.bulkCreate(<module String>,<dataList List>,<optionalDataMap Map>,<connectionName String>,<userAccess Boolean>);
mandatory : module,dataList
Sample Request:
resp = zoho.crm.bulkCreate("Price_Books", [{"Owner": {"id": "7000000031553"},"Active": true,"Pricing_Details": [{"to_range": 5,"discount": 0,"from_range": 1},{"to_range": 11,"discount": 1,"from_range": 6},{"to_range": 17,"discount": 2,"from_range": 12},{"to_range": 23,"discount": 3,"from_range": 18},{"to_range": 29,"discount": 4,"from_range": 24}],"Pricing_Model": "Differential","Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.","Price_Book_Name": "Price_Book_Name oops1"},{"Owner": {"id": "7000000031553"},"Active": true,"Pricing_Details": [{"to_range": 5,"discount": 0,"from_range": 1},{"to_range": 11,"discount": 1,"from_range": 6},{"to_range": 17,"discount": 2,"from_range": 12},{"to_range": 23,"discount": 3,"from_range": 18},{"to_range": 29,"discount": 4,"from_range": 24}],"Pricing_Model": "Differential","Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.","Price_Book_Name": "Price_Book_Name oops2"}]);
In the request, "@newlead.json" contains the sample input data.