Create Bulk Write Job
Purpose
To create a bulk write job to import records into CRM.
Endpoints
Request Details
Request URL
https://www.zohoapis.com/crm/bulk/v2/write
Header
Authorization: Zoho-oauthtoken d92d4xxxxxxxxxxxxx15f52
Scope
scope=ZohoCRM.bulk.CREATE
(or)
scope=ZohoCRM.bulk.ALL
(and)
scope=ZohoCRM.modules.ALL
(or)
scope=ZohoCRM.modules.{module_name}.{operation_type}
Possible module names
leads, accounts, contacts, deals, campaigns, cases, solutions, products, vendors, pricebooks, and custom
Possible operation types
ALL - Full access to the record
CREATE - Create a bulk write job
Sample request
Copiedcurl "https://www.zohoapis.com/crm/bulk/v2/write"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-d "@inputData.json"
CopiedString moduleAPIName = "Leads";
String fileId = "3477061000006121001";
//Get instance of BulkWriteOperations Class
BulkWriteOperations bulkWriteOperations = new BulkWriteOperations();
//Get instance of RequestWrapper Class that will contain the request body
RequestWrapper requestWrapper = new RequestWrapper();
//Get instance of CallBack Class
CallBack callback = new CallBack();
// To set valid callback URL.
callback.setUrl("https://www.example.com/callback");
//To set the HTTP method of the callback URL. The allowed value is post.
callback.setMethod(new Choice < String > ("post"));
//The Bulk Write Job's details are posted to this URL on successful completion of job or on failure of job.
requestWrapper.setCallback(callback);
//To set the charset of the uploaded file
requestWrapper.setCharacterEncoding("UTF-8");
//To set the type of operation you want to perform on the bulk write job.
requestWrapper.setOperation(new Choice < String > ("insert"));
List < Resource > resource = new ArrayList < Resource > ();
//Get instance of Resource Class
Resource resourceIns = new Resource();
// To set the type of module that you want to import. The value is data.
resourceIns.setType(new Choice < String > ("data"));
//To set API name of the module that you select for bulk write job.
resourceIns.setModule(moduleAPIName);
//To set the file_id obtained from file upload API.
resourceIns.setFileId(fileId);
//True - Ignores the empty values.The default value is false.
resourceIns.setIgnoreEmpty(true);
// To set a field as a unique field or ID of a record.
//resourceIns.setFindBy("");
List < FieldMapping > fieldMappings = new ArrayList < FieldMapping > ();
FieldMapping fieldMapping;
//Get instance of FieldMapping Class
fieldMapping = new FieldMapping();
//To set API name of the field present in Zoho module object that you want to import.
fieldMapping.setAPIName("Last_Name");
//To set the column index of the field you want to map to the CRM field.
fieldMapping.setIndex(0);
fieldMappings.add(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Email");
fieldMapping.setIndex(1);
fieldMappings.add(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Company");
fieldMapping.setIndex(2);
fieldMappings.add(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Phone");
fieldMapping.setIndex(3);
fieldMappings.add(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Website");
//fieldMapping.setFormat("");
//fieldMapping.setFindBy("");
Map < String, Object > defaultValue = new HashMap < String, Object > ();
defaultValue.put("value", "https://www.zohoapis.com");
//To set the default value for an empty column in the uploaded file.
fieldMapping.setDefaultValue(defaultValue);
fieldMappings.add(fieldMapping);
resourceIns.setFieldMappings(fieldMappings);
resource.add(resourceIns);
requestWrapper.setResource(resource);
//Call createBulkWriteJob method that takes RequestWrapper instance as parameter
APIResponse < ActionResponse > response = bulkWriteOperations.createBulkWriteJob(requestWrapper);
Copiedimport javax.net.ssl.SSLContext;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
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 CreateBulkWriteJob
{
@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/bulk/v2/write");
HttpUriRequest requestObj = new HttpPost(uriBuilder.build());
HttpEntityEnclosingRequestBase requestBase = (HttpEntityEnclosingRequestBase) requestObj;
JSONObject requestBody = new JSONObject();
requestBody.put("operation", "insert");
JSONObject callback = new JSONObject();
callback.put("url", "https://www.example.com/callback");
callback.put("method", "post");
requestBody.put("callback", callback);
requestBody.put("character_encoding", "UTF-8");
JSONArray resource = new JSONArray();
JSONObject resourceObject = new JSONObject();
resourceObject.put("type", "data");
// resourceObject.put("find_by", "Email");
resourceObject.put("file_id", "111111000001492610");
resourceObject.put("module", "Leads");
resourceObject.put("ignore_empty", true);
JSONArray fieldMappings = new JSONArray();
JSONObject fieldMapping = new JSONObject();
fieldMapping.put("api_name", "Last_Name");
fieldMapping.put("index", 0);
fieldMappings.put(fieldMapping);
fieldMapping = new JSONObject();
fieldMapping.put("api_name", "Email");
fieldMapping.put("index", 1);
fieldMappings.put(fieldMapping);
fieldMapping = new JSONObject();
fieldMapping.put("api_name", "Company");
fieldMapping.put("index", 2);
fieldMappings.put(fieldMapping);
fieldMapping = new JSONObject();
fieldMapping.put("api_name", "Phone");
fieldMapping.put("index", 3);
fieldMappings.put(fieldMapping);
fieldMapping = new JSONObject();
fieldMapping.put("api_name", "Website");
JSONObject defaultValue = new JSONObject();
defaultValue.put("value", "https://www.zohoapis.com");
fieldMapping.put("default_value", defaultValue);
fieldMappings.put(fieldMapping);
resourceObject.put("field_mappings", fieldMappings);
resource.put(resourceObject);
requestBody.put("resource", resource);
requestBase.setEntity(new StringEntity(requestBody.toString(), HTTP.UTF_8));
requestObj.addHeader("Authorization", "Zoho-oauthtoken 1000.xxxxxxx.xxxxxxx");
requestObj.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");
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//Get instance of BulkWriteOperations Class
$bulkWriteOperations = new BulkWriteOperations();
//Get instance of RequestWrapper Class that will contain the request body
$requestWrapper = new RequestWrapper();
//Get instance of CallBack Class
$callback = new CallBack();
// To set valid callback URL.
$callback->setUrl("https://www.example.com/callback");
//To set the HTTP method of the callback URL. The allowed value is post.
$callback->setMethod(new Choice("post"));
//The Bulk Write Job's details are posted to this URL on successful completion of job or on failure of job.
$requestWrapper->setCallback($callback);
//To set the charset of the uploaded file
$requestWrapper->setCharacterEncoding("UTF-8");
//To set the type of operation you want to perform on the bulk write job.
$requestWrapper->setOperation(new Choice("insert"));
$resource = array();
//Get instance of Resource Class
$resourceIns = new Resource();
// To set the type of module that you want to import. The value is data.
$resourceIns->setType(new Choice("data"));
//To set API name of the module that you select for bulk write job.
$resourceIns->setModule($moduleAPIName);
//To set the file_id obtained from file upload API.
$resourceIns->setFileId($fileId);
//True - Ignores the empty values.The default value is false.
$resourceIns->setIgnoreEmpty(true);
// To set a field as a unique field or ID of a record.
//resourceIns.setFindBy("");
$fieldMappings = array();
//Get instance of FieldMapping Class
$fieldMapping = new FieldMapping();
//To set API name of the field present in Zoho module object that you want to import.
$fieldMapping->setAPIName("Last_Name");
//To set the column index of the field you want to map to the CRM field.
$fieldMapping->setIndex(0);
array_push($fieldMappings, $fieldMapping);
$fieldMapping = new FieldMapping();
$fieldMapping->setAPIName("Email");
$fieldMapping->setIndex(1);
array_push($fieldMappings, $fieldMapping);
$fieldMapping = new FieldMapping();
$fieldMapping->setAPIName("Company");
$fieldMapping->setIndex(2);
array_push($fieldMappings, $fieldMapping);
$fieldMapping = new FieldMapping();
$fieldMapping->setAPIName("Phone");
$fieldMapping->setIndex(3);
array_push($fieldMappings, $fieldMapping);
$fieldMapping = new FieldMapping();
$fieldMapping->setAPIName("Website");
//$fieldMapping->setFormat("");
//$fieldMapping->setFindBy("");
$defaultValue = array();
$defaultValue["value"] = "https://www.zohoapis.com";
//To set the default value for an empty column in the uploaded file.
$fieldMapping->setDefaultValue($defaultValue);
array_push($fieldMappings, $fieldMapping);
$resourceIns->setFieldMappings($fieldMappings);
array_push($resource, $resourceIns);
$requestWrapper->setResource($resource);
//Call createBulkWriteJob method that takes RequestWrapper instance as parameter
$response = $bulkWriteOperations->createBulkWriteJob($requestWrapper);
Copied<?php
class CreateBulkWriteJob
{
public function execute(){
$curl_pointer = curl_init();
$curl_options = array();
$curl_options[CURLOPT_URL] = "https://www.zohoapis.com/crm/bulk/v2/read";
$curl_options[CURLOPT_RETURNTRANSFER] = true;
$curl_options[CURLOPT_HEADER] = 1;
$curl_options[CURLOPT_CUSTOMREQUEST] = "POST";
$requestBody = array();
$callback = array();
$callback["url"]="https://www.example.com/callback";
$callback["method"]="post";
$query = array();
$query["module"]="Contacts";
$fields = array();
$fields[] = "Last_Name";
$fields[] = "Owner";
$fields[] = "Owner.last_name";
$fields[] = "Account_Name.Account_Name";
$fields[] = "Account_Name.Phone";
$fields[] = "Lead_Source";
$fields[] = "Created_Time";
$requestBody["callback"] =$callback;
$query["fields"]=$fields;
$criteria = array();
$criteria["group_operator"]="or";
$group = array();
$criteria1 = array();
$criteria1["api_name"]="Lead_Source";
$criteria1["comparator"]="equal";
$criteria1["value"]="Advertisement";
$criteria2 = array();
$criteria2["api_name"]="Owner.last_name";
$criteria2["comparator"]="equal";
$criteria2["value"]="Boyle";
$criteria3 = array();
$criteria3["api_name"]="Account_Name.Phone";
$criteria3["comparator"]="contains";
$criteria3["value"]="5";
$group = [$criteria1,$criteria2,$criteria3];
$criteria["group"] = $group;
$query["criteria"] =$criteria;
$query["page"] =1;
$requestBody["query"]=$query;
$curl_options[CURLOPT_POSTFIELDS]= json_encode($requestBody);
$headersArray = array();
$headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " ."1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf";
$headersArray[] = "Content-Type".":"."application/json";
$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 CreateBulkWriteJob())->execute();
Copied//Get instance of BulkWriteOperations Class
BulkWriteOperations bulkWriteOperations = new BulkWriteOperations();
//Get instance of RequestWrapper Class that will contain the request body
RequestWrapper requestWrapper = new RequestWrapper();
//Get instance of CallBack Class
CallBack callback = new CallBack();
// To set valid callback URL.
callback.Url = "https://www.example.com/callback";
//To set the HTTP method of the callback URL. The allowed value is post.
callback.Method = new Choice<string>("post");
//The Bulk Write Job's details are posted to this URL on successful completion of job or on failure of job.
requestWrapper.Callback = callback;
//To set the charset of the uploaded file
requestWrapper.CharacterEncoding = "UTF-8";
//To set the type of operation you want to perform on the bulk write job.
requestWrapper.Operation = new Choice<string>("update");
List<Resource> resource = new List<Resource>();
//Get instance of Resource Class
Resource resourceIns = new Resource();
// To set the type of module that you want to import. The value is data.
resourceIns.Type = new Choice<string>("data");
//To set API name of the module that you select for bulk write job.
resourceIns.Module = moduleAPIName;
//To set the file_id obtained from file upload API.
resourceIns.FileId = fileId;
//True - Ignores the empty values.The default value is false.
resourceIns.IgnoreEmpty = true;
// To set a field as a unique field or ID of a record.
resourceIns.FindBy = "Email";
List<FieldMapping> fieldMappings = new List<FieldMapping>();
FieldMapping fieldMapping;
//Get instance of FieldMapping Class
fieldMapping = new FieldMapping();
//To set API name of the field present in Zoho module object that you want to import.
fieldMapping.APIName = "Last_Name";
//To set the column index of the field you want to map to the CRM field.
fieldMapping.Index = 0;
fieldMappings.Add(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.APIName = "Email";
fieldMapping.Index = 1;
fieldMappings.Add(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.APIName = "Company";
fieldMapping.Index = 2;
fieldMappings.Add(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.APIName = "Phone";
fieldMapping.Index = 3;
fieldMappings.Add(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.APIName = "Website";
//fieldMapping.Format = "";
//fieldMapping.FindBy = "";
Dictionary<string, object> defaultValue = new Dictionary<string, object>();
defaultValue.Add("value", "https://www.zohoapis.com");
//To set the default value for an empty column in the uploaded file.
fieldMapping.DefaultValue = defaultValue;
fieldMappings.Add(fieldMapping);
resourceIns.FieldMappings = fieldMappings;
resource.Add(resourceIns);
requestWrapper.Resource = resource;
//Call CreateBulkWriteJob method that takes RequestWrapper instance as parameter
APIResponse<ActionResponse> response = bulkWriteOperations.CreateBulkWriteJob(requestWrapper);
Copiedusing System;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json.Linq;
namespace Com.Zoho.Crm.API.Sample.RestAPI.BulkWrite
{
public class CreateBulkWriteJob
{
public static void CreateBulkWrite()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.zohoapis.com/crm/bulk/v2/write");
request.Method = "POST";
request.ContentType = "application/json";
request.Headers["Authorization"] = "Zoho-oauthtoken 1000.abfeXXXXXXXXXXX2asw.XXXXXXXXXXXXXXXXXXsdc2";
JObject requestBody = new JObject();
requestBody.Add("operation", "insert");
JObject callback = new JObject();
callback.Add("url", "https://www.example.com/callback");
callback.Add("method", "post");
requestBody.Add("callback", callback);
requestBody.Add("character_encoding", "UTF-8");
JArray resource = new JArray();
JObject resourceObject = new JObject();
resourceObject.Add("type", "data");
// resourceObject.Add("find_by", "Email");
resourceObject.Add("file_id", "34770617819001");
resourceObject.Add("module", "Leads");
resourceObject.Add("ignore_empty", true);
JArray fieldMappings = new JArray();
JObject fieldMapping = new JObject();
fieldMapping.Add("api_name", "Last_Name");
fieldMapping.Add("index", 0);
fieldMappings.Add(fieldMapping);
fieldMapping = new JObject();
fieldMapping.Add("api_name", "Email");
fieldMapping.Add("index", 1);
fieldMappings.Add(fieldMapping);
fieldMapping = new JObject();
fieldMapping.Add("api_name", "Company");
fieldMapping.Add("index", 2);
fieldMappings.Add(fieldMapping);
fieldMapping = new JObject();
fieldMapping.Add("api_name", "Phone");
fieldMapping.Add("index", 3);
fieldMappings.Add(fieldMapping);
fieldMapping = new JObject();
fieldMapping.Add("api_name", "Website");
JObject defaultValue = new JObject();
defaultValue.Add("value", "https://www.zohoapis.com");
fieldMapping.Add("default_value", defaultValue);
fieldMappings.Add(fieldMapping);
resourceObject.Add("field_mappings", fieldMappings);
resource.Add(resourceObject);
requestBody.Add("resource", resource);
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# Get instance of BulkWriteOperations Class
bulk_write_operations = BulkWriteOperations()
# Get instance of RequestWrapper Class that will contain the request body
request = RequestWrapper()
# Get instance of CallBack Class
call_back = CallBack()
# Set valid callback URL
call_back.set_url("https://www.example.com/callback")
# Set the HTTP method of the callback URL. The allowed value is post.
call_back.set_method(Choice('post'))
# The Bulk Read Job's details is posted to this URL on successful completion / failure of the job.
request.set_callback(call_back)
# Set the charset of the uploaded file
request.set_character_encoding('UTF-8')
# To set the type of operation you want to perform on the bulk write job.
request.set_operation(Choice('insert'))
resources = []
# Get instance of Resource Class
resource = Resource()
# To set the type of module that you want to import. The value is data.
resource.set_type(Choice('data'))
# To set API name of the module that you select for bulk write job.
resource.set_module(module_api_name)
# To set the fileId obtained from file upload API.
resource.set_file_id(file_id)
# True - Ignores the empty values.The default value is false.
resource.set_ignore_empty(True)
# To set a field as a unique field or ID of a record.
# resource.set_find_by('Email')
field_mappings = []
# Get instance of FieldMapping Class
field_mapping = FieldMapping()
# To set API name of the field present in Zoho module object that you want to import.
field_mapping.set_api_name('Email')
# To set the column index of the field you want to map to the CRM field.
field_mapping.set_index(0)
field_mappings.append(field_mapping)
field_mapping = FieldMapping()
# To set API name of the field present in Zoho module object that you want to import.
field_mapping.set_api_name('First_Name')
# To set the column index of the field you want to map to the CRM field.
field_mapping.set_index(1)
field_mappings.append(field_mapping)
field_mapping = FieldMapping()
# To set API name of the field present in Zoho module object that you want to import.
field_mapping.set_api_name('Last_Name')
# To set the column index of the field you want to map to the CRM field.
field_mapping.set_index(2)
field_mappings.append(field_mapping)
field_mapping = FieldMapping()
# To set API name of the field present in Zoho module object that you want to import.
field_mapping.set_api_name('Phone')
# To set the column index of the field you want to map to the CRM field.
field_mapping.set_index(3)
field_mappings.append(field_mapping)
field_mapping = FieldMapping()
default_value = dict()
default_value["value"] = "www.zohoapis.com"
# To set the default value for an empty column in the uploaded file.
field_mapping.set_default_value(default_value)
field_mappings.append(field_mapping)
resource.set_field_mappings(field_mappings)
resources.append(resource)
# Set the list of resources to RequestWrapper instance
request.set_resource(resources)
# Call create_bulk_write_job method that takes RequestWrapper instance as parameter
response = bulk_write_operations.create_bulk_write_job(request)
Copieddef create_bulk_write_job():
import requests
import json
url = 'https://www.zohoapis.com/crm/bulk/v2/write'
headers = {
'Authorization': 'Zoho-oauthtoken 1000.04be928e4a96XXXXXXXXXXXXX68.0b9eXXXXXXXXXXXX60396e268',
'Content-Type': 'application/json'
}
request_body = dict()
request_body['operation'] = 'insert'
call_back = {
'url': 'https://www.example.com/callback',
'method': 'post'
}
request_body['callback'] = call_back
request_body['character_encoding'] = 'UTF-8'
resource = list()
resource_object = {
'type': 'data',
'file_id': '111111000001492610',
'module': 'Leads',
}
field_mapping_1 = {
'api_name': 'Last_Name',
'index': 0
}
field_mapping_2 = {
'api_name': 'Email',
'index': 1
}
field_mapping_3 = {
'api_name': 'Company',
'index': 2
}
field_mapping_4 = {
'api_name': 'Phone',
'index': 3
}
field_mapping_5 = {
'api_name': 'Website',
'default_value': {
'value': 'https://www.zohoapis.com'
}
}
field_mappings = [
field_mapping_1,
field_mapping_2,
field_mapping_3,
field_mapping_4,
field_mapping_5
]
resource_object['field_mappings'] = field_mappings
resource.append(resource_object)
request_body['resource'] = resource
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())
create_bulk_write_job()
Copied//Get instance of BulkWriteOperations Class
let bulkWriteOperations = new BulkWriteOperations();
//Get instance of RequestWrapper Class that will contain the request body
let requestWrapper = new RequestWrapper();
//Get instance of CallBack Class
let callBack = new CallBack();
//Set valid callback URL.
callBack.setUrl("https://www.example.com/callback");
//Set the HTTP method of the callback URL. The allowed value is post.
callBack.setMethod(new Choice("post"));
//The Bulk Write Job's details are posted to this URL on successful completion / failure of the job.
requestWrapper.setCallback(callBack);
//Set the charset of the uploaded file
requestWrapper.setCharacterEncoding("UTF-8");
//To set the type of operation you want to perform on the bulk write job.
requestWrapper.setOperation(new Choice("insert"));
let resources = [];
//Get instance of Resource Class
let resource = new Resource();
// To set the type of module that you want to import. The value is data.
resource.setType(new Choice("data"));
//To set API name of the module that you select for bulk write job.
resource.setModule(moduleAPIName);
//To set the fileId obtained from file upload API.
resource.setFileId(fileId);
//True - Ignores the empty values.The default value is false.
resource.setIgnoreEmpty(true);
// To set a field as a unique field or ID of a record.
// resource.setFindBy("Email");
let fieldMappings = [];
//Get instance of FieldMapping Class
let fieldMapping = new FieldMapping();
//To set API name of the field present in Zoho module object that you want to import.
fieldMapping.setAPIName("Last_Name");
//To set the column index of the field you want to map to the CRM field.
fieldMapping.setIndex(0);
fieldMappings.push(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Email");
fieldMapping.setIndex(1);
fieldMappings.push(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Company");
fieldMapping.setIndex(2);
fieldMappings.push(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Phone");
fieldMapping.setIndex(3);
fieldMappings.push(fieldMapping);
let defaultValue = new Map();
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Website");
defaultValue.set("value", "www.zohoapis.com");
//To set the default value for an empty column in the uploaded file.
fieldMapping.setDefaultValue(defaultValue);
fieldMappings.push(fieldMapping);
resource.setFieldMappings(fieldMappings);
resources.push(resource);
//Set the array of resources to RequestWrapper instance
requestWrapper.setResource(resources);
//Call createBulkWriteJob method that takes RequestWrapper instance as parameter
let response = await bulkWriteOperations.createBulkWriteJob(requestWrapper);
Copiedasync function createBulkWriteJob() {
const got = require('got');
let url = 'https://www.zohoapis.com/crm/bulk/v2/write'
let headers = {
'Authorization': 'Zoho-oauthtoken 1000.04be928e4a9653ec5995ac4d5ca17c68.0b9e25ccbe5c6afe5f579e860396e268',
'Content-Type': 'application/json'
}
let requestBody = {}
requestBody['operation'] = 'insert'
let callBack = {
'url': 'https://www.example.com/callback',
'method': 'post'
}
requestBody['callback'] = callBack
requestBody['character_encoding'] = 'UTF-8'
let resource = []
let resourceObject = {
'type': 'data',
'file_id': '111111000001492610',
'module': 'Leads',
}
let fieldMapping1 = {
'api_name': 'Last_Name',
'index': 0
}
let fieldMapping2 = {
'api_name': 'Email',
'index': 1
}
let fieldMapping3 = {
'api_name': 'Company',
'index': 2
}
let fieldMapping4 = {
'api_name': 'Phone',
'index': 3
}
let fieldMapping5 = {
'api_name': 'Website',
'default_value': {
'value': 'https://www.zohoapis.com'
}
}
let fieldMappings = [
fieldMapping1,
fieldMapping2,
fieldMapping3,
fieldMapping4,
fieldMapping5
]
resourceObject['field_mappings'] = fieldMappings
resource.push(resourceObject)
requestBody['resource'] = resource
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);
}
}
createBulkWriteJob()
Copied# """
cvid = '3524033000000087501'
# Get instance of BulkWriteOperations Class
bwo = BulkWrite::BulkWriteOperations.new
# Get instance of RequestWrapper Class that will contain the request body
request_wrapper = BulkWrite::RequestWrapper.new
# Get instance of CallBack Class
call_back = BulkWrite::CallBack.new
# Set valid callback URL
call_back.url = 'https://www.example.com/callback'
# Set the HTTP method of the callback URL. The allowed value is post.
call_back.method = Util::Choice.new('post')
# The Bulk Read Job's details is posted to this URL on successful completion / failure of the job.
request_wrapper.callback = call_back
# Set the charset of the uploaded file
request_wrapper.character_encoding = 'UTF-8'
# To set the type of operation you want to perform on the bulk write job.
request_wrapper.operation = Util::Choice.new('insert')
# Get instance of Resource Class
resource_ins = BulkWrite::Resource.new
# To set the type of module that you want to import. The value is data.
resource_ins.type = Util::Choice.new('data')
# To set API name of the module that you select for bulk write job.
resource_ins.module = module_api_name
# To set the fileId obtained from file upload API.
resource_ins.file_id = file_id
# True - Ignores the empty values.The default value is false.
resource_ins.ignore_empty = true
# Get instance of FieldMapping Class
field_mapping0 = BulkWrite::FieldMapping.new
# To set API name of the field present in Zoho module object that you want to import.
field_mapping0.api_name = 'Last_Name'
# To set the column index of the field you want to map to the CRM field.
field_mapping0.index = 0
field_mapping1 = BulkWrite::FieldMapping.new
field_mapping1.api_name = 'Email'
field_mapping1.index = 1
field_mapping2 = BulkWrite::FieldMapping.new
field_mapping2.api_name = 'Company'
field_mapping2.index = 2
field_mapping3 = BulkWrite::FieldMapping.new
field_mapping3.api_name = 'Phone'
field_mapping3.index = 3
field_mapping4 = BulkWrite::FieldMapping.new
field_mapping4.api_name = 'Website'
# To set the default value for an empty column in the uploaded file.
default_value = { 'value' => 'https://www.zohoapis.com' }
# To set the default value for an empty column in the uploaded file.
field_mapping4.default_value = default_value
field_mappings = [field_mapping0, field_mapping1, field_mapping2, field_mapping3, field_mapping4]
resource_ins.field_mappings = field_mappings
resource = [resource_ins]
# Set the list of resources to RequestWrapper instance
request_wrapper.resource = resource
# Call create_bulk_write_job method that takes RequestWrapper instance as parameter
response = bwo.create_bulk_write_job(request_wrapper)
Copiedclass CreateBulkWriteJob
def execute
url ="https://www.zohoapis.com/crm/bulk/v2/write";
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.50XXXXXXXXX&77e3a.44XXXXXXXXX8353"
headers["Content-Type"]="application/json";
headers&.each { |key, value| req.add_field(key, value) }
request_body = {};
callback = {}
callback["url"]="https://www.example.com/callback";
callback["method"]="post";
query = {}
query["module"]="Contacts";
fields = ["Last_Name","Owner","Owner.last_name","Account_Name.Account_Name"]
request_body["callback"] =callback;
query["fields"]=fields;
criteria = {}
criteria["group_operator"]="or";
group = {}
criteria1 = {}
criteria1["api_name"]="Lead_Source";
criteria1["comparator"]="equal";
criteria1["value"]="Advertisement";
criteria2 = {}
criteria2["api_name"]="Owner.last_name";
criteria2["comparator"]="equal";
criteria2["value"]="Boyle";
criteria3 = {}
criteria3["api_name"]="Account_Name.Phone";
criteria3["comparator"]="contains";
criteria3["value"]="5";
group = [criteria1,criteria2,criteria3];
criteria["group"] = group;
query["criteria"] =criteria;
query["page"] =1;
request_body["query"]=query;
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
CreateBulkWriteJob.new.execute
Copied//Get instance of BulkWriteOperations Class
let bulkWriteOperations = new ZCRM.BulkWrite.Operations();
//Get instance of RequestWrapper Class that will contain the request body
let requestWrapper = new ZCRM.BulkWrite.Model.RequestWrapper();
//Get instance of CallBack Class
let callBack = new ZCRM.BulkWrite.Model.CallBack();
//Set valid callback URL.
callBack.setUrl("https://www.example.com/callback");
//Set the HTTP method of the callback URL. The allowed value is post.
callBack.setMethod(new Choice("post"));
//The Bulk Write Job's details are posted to this URL on successful completion / failure of the job.
requestWrapper.setCallback(callBack);
//Set the charset of the uploaded file
requestWrapper.setCharacterEncoding("UTF-8");
//To set the type of operation you want to perform on the bulk write job.
requestWrapper.setOperation(new Choice("insert"));
let resources = [];
//Get instance of Resource Class
let resource = new ZCRM.BulkWrite.Model.Resource();
// To set the type of module that you want to import. The value is data.
resource.setType(new Choice("data"));
//To set API name of the module that you select for bulk write job.
resource.setModule(moduleAPIName);
//To set the fileId obtained from file upload API.
resource.setFileId(fileId);
//True - Ignores the empty values.The default value is false.
resource.setIgnoreEmpty(true);
// To set a field as a unique field or ID of a record.
// resource.setFindBy("Email");
let fieldMappings = [];
//Get instance of FieldMapping Class
let fieldMapping = new ZCRM.BulkWrite.Model.FieldMapping();
//To set API name of the field present in Zoho module object that you want to import.
fieldMapping.setAPIName("Last_Name");
//To set the column index of the field you want to map to the CRM field.
fieldMapping.setIndex(0);
fieldMappings.push(fieldMapping);
fieldMapping = new ZCRM.BulkWrite.Model.FieldMapping();
fieldMapping.setAPIName("Email");
fieldMapping.setIndex(1);
fieldMappings.push(fieldMapping);
fieldMapping = new ZCRM.BulkWrite.Model.FieldMapping();
fieldMapping.setAPIName("Company");
fieldMapping.setIndex(2);
fieldMappings.push(fieldMapping);
fieldMapping = new ZCRM.BulkWrite.Model.FieldMapping();
fieldMapping.setAPIName("Phone");
fieldMapping.setIndex(3);
fieldMappings.push(fieldMapping);
let defaultValue = new Map();
fieldMapping = new ZCRM.BulkWrite.Model.FieldMapping();
fieldMapping.setAPIName("Website");
defaultValue.set("value", "www.zohoapis.com");
//To set the default value for an empty column in the uploaded file.
fieldMapping.setDefaultValue(defaultValue);
fieldMappings.push(fieldMapping);
resource.setFieldMappings(fieldMappings);
resources.push(resource);
//Set the array of resources to RequestWrapper instance
requestWrapper.setResource(resources);
//Call createBulkWriteJob method that takes RequestWrapper instance as parameter
let response = await bulkWriteOperations.createBulkWriteJob(requestWrapper);
Copiedvar listener = 0;
class CreateBulkWriteJob {
async createBulkWriteJob() {
var url = "https://www.zohoapis.com/crm/bulk/v2/write"
var parameters = new Map()
var headers = new Map()
var token = {
clientId:"1000.NPY9M1V0XXXXXXXXXXXXXXXXXXXF7H",
redirectUrl:"http://127.0.0.1:5501/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 CreateBulkWriteJob().getToken(token)
headers.set("Authorization", "Zoho-oauthtoken " + accesstoken)
headers.set("Content-Type", "application/json")
var requestMethod = "POST"
var reqBody = {
"operation": "insert",
"callback": {
"url": "https://www.example.com/callback",
"method": "post"
},
"resource": [
{
"type": "data",
"module": "Leads",
"file_id": "111111000001492610",
"field_mappings": [
{
"api_name": "Last_Name",
"index": 0
},
{
"api_name": "Email",
"index": 1
},
{
"api_name": "Company",
"index": 2
},
{
"api_name": "Phone",
"index": 3
},
{
"api_name": "Website",
"default_value": {
"value": "www.zohoapis.com"
}
}
]
}
]
}
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 CreateBulkWriteJob().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){ // check after 59th minute
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);
}
}
})
}
}
Copied//Get instance of BulkWriteOperations Class
let bulkWriteOperations: BulkWriteOperations = new BulkWriteOperations();
//Get instance of RequestWrapper Class that will contain the request body
let requestWrapper: RequestWrapper = new RequestWrapper();
//Get instance of CallBack Class
let callBack: CallBack = new CallBack();
//Set valid callback URL.
callBack.setUrl("https://www.example.com/callback");
//Set the HTTP method of the callback URL. The allowed value is post.
callBack.setMethod(new Choice("post"));
//The Bulk Write Job's details are posted to this URL on successful completion / failure of the job.
requestWrapper.setCallback(callBack);
//Set the charset of the uploaded file
requestWrapper.setCharacterEncoding("UTF-8");
//To set the type of operation you want to perform on the bulk write job.
requestWrapper.setOperation(new Choice("insert"));
let resources: Resource[] = [];
//Get instance of Resource Class
let resource: Resource = new Resource();
// To set the type of module that you want to import. The value is data.
resource.setType(new Choice("data"));
//To set API name of the module that you select for bulk write job.
resource.setModule(moduleAPIName);
//To set the fileId obtained from file upload API.
resource.setFileId(fileId);
//True - Ignores the empty values.The default value is false.
resource.setIgnoreEmpty(true);
// To set a field as a unique field or ID of a record.
// resource.setFindBy("Email");
let fieldMappings: FieldMapping[] = [];
//Get instance of FieldMapping Class
let fieldMapping: FieldMapping = new FieldMapping();
//To set API name of the field present in Zoho module object that you want to import.
fieldMapping.setAPIName("Last_Name");
//To set the column index of the field you want to map to the CRM field.
fieldMapping.setIndex(0);
fieldMappings.push(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Email");
fieldMapping.setIndex(1);
fieldMappings.push(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Company");
fieldMapping.setIndex(2);
fieldMappings.push(fieldMapping);
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Phone");
fieldMapping.setIndex(3);
fieldMappings.push(fieldMapping);
let defaultValue: Map < string, string > = new Map < string,
string > ();
fieldMapping = new FieldMapping();
fieldMapping.setAPIName("Website");
defaultValue.set("value", "www.zohoapis.com");
//To set the default value for an empty column in the uploaded file.
fieldMapping.setDefaultValue(defaultValue);
fieldMappings.push(fieldMapping);
resource.setFieldMappings(fieldMappings);
resources.push(resource);
//Set the array of resources to RequestWrapper instance
requestWrapper.setResource(resources);
//Call createBulkWriteJob method that takes RequestWrapper instance as parameter
let response: APIResponse < ActionResponse > = await bulkWriteOperations.createBulkWriteJob(requestWrapper);
Copiedimport got from 'got';
class CreateBulkWriteJob {
public async main() {
var apiHeaders: {[key: string]: string} = {};
var apiParameters: {[key: string]: string} = {};
var modifiedRequestBody: any= {
"operation": "insert",
"callback": {
"url": "https://www.example.com/callback",
"method": "post"
},
"resource": [
{
"type": "data",
"module": "Leads",
"file_id": "34770619331003",
"field_mappings": [
{
"api_name": "Last_Name",
"index": 0
},
{
"api_name": "Email",
"index": 1
},
{
"api_name": "Company",
"index": 2
},
{
"api_name": "Phone",
"index": 3
},
{
"api_name": "Website",
"default_value": {
"value": "www.zohoapis.com"
}
}
]
}
]
};
modifiedRequestBody = JSON.stringify(modifiedRequestBody)
apiHeaders["Content-Type"]= "application/json"
apiHeaders["Authorization"] = "Zoho-oauthtoken 1000.xxxxxxx.xxxxxx"
var requestDetails: {[key: string]: any} = {
method : "POST",
headers : apiHeaders,
searchParams : apiParameters,
body : modifiedRequestBody,
encoding: "utf8",
allowGetBody : true,
throwHttpErrors : false
};
var response = await got("https://www.zohoapis.com/crm/bulk/v2/write", requestDetails);
console.log(response.statusCode)
console.log(JSON.parse(response.body));
}
}
var v = new CreateBulkWriteJob()
v.main()
Request JSON
- character_encodingString, optional
Represents the charset of the uploaded file. It is usually auto-detected, but if specified, then it will be used to read the file.
- operationString, mandatory
Represents the type of operation you want to perform on the bulk write job.
Values are
- insert - To create CSV records as new records in CRM.
- update - To update an existing record in CRM(This operation does not allow creation of new records).
- upsert - To update an existing record in CRM and create new records, if they do not exist already.
- ignore_emptyBoolean, optional
True - Ignores the empty values in a column and updates only the fields of a record without empty values
False or empty - The system updates records in CRM with empty values in the given file column.
The default value is false. - callbackJSON Object, optional
A valid URL that allows the HTTP POST method. The Bulk Write Job's details are posted to this URL on successful completion or failure of a job. Sample - "callback" : { "url": "https://sampledomain.com/getzohoresponse", "method": "post" }.
This JSON Object takes two keys—url and method.- url(string) - A valid URL, which should allow HTTP POST method. The Bulk Write Job's details are posted to this URL on successful completion or failure of a job.
- method(string) - The HTTP method of the callback url. The supported value is post.
- resourceJSON array, optional
A JSON array of objects containing the API names of modules that you want to import, their field mappings, and the corresponding file IDs obtained from Upload API.
- type(string, mandatory) - Represents the type of module that you want to import. The value is data.
- module(string, mandatory) - The API name of the module that you select for bulk write job.
For subforms: When you want to bulk-write subform data, you must give the API name of the subform here. - file_id(string, mandatory) - The file_id obtained from file upload API.
- find_by(string, mandatory for update and upsert, optional for insert) - The API name of a unique field or ID of a record. The system uses the value of this field to find the existing records in CRM. When you specify this parameter for insert operation, the system will skip the existing records from the file.
- field_mappings(JSON array, optional) - When the system processes a CSV file, the first row is treated as the header row. Each header name is treated as the field API name and data from a column are populated into the corresponding field represented by the API name. This parameter helps you to skip auto-mapping and define your own field mapping. Note that if you include this array in the input, data in the CSV will be mapped based only on the index value in this array.
- api_name(string, mandatory) - The API name of the field present in Zoho module object that you want to import. Refer Fields Meta Data API for the list of fields available in a module. An invalid field API name throws an error.
- index(number, optional) - The column index of the field you want to map to the CRM field. When you specify a non-existing index value, the system throws an error.
- find_by(string, mandatory for lookup fields) - The API name of the unique field in the module against which the system checks if there are existing records in CRM. You can also use id, API names of the system-defined unique fields, custom unique fields, lookup fields, and display columns/fields(the results displayed based on a field, that are listed when you search for an associated lookup. For example, Account Name is the display column when you have a look up in Contacts that points to Accounts.) as find_by fields.
- default_value(JSON object, optional) - Use this key if some of the records do not have a value in a column, and you want to replace it with a default value. Example: {"value": "Trade Show"}.
Notes
For Subforms
The field_mappings array must have the following mandatory object, besides the details of the other fields of the subform. This is to map the subform record with the respective parent record.
"api_name":"Parent_Id", "find_by":"id", "index":"the_index_in_the_csv"
For Custom Layout
To map the bulk data data into a specific layout, you must specify the unique ID of the custom Layout, under the default_Value JSON Object.
Example:
"api_name": "Layout", "default_value": { "value": "{custom Layout ID}" }
You can get layout ID from the Metadata Layouts API.
- You can bulk-insert records in a specific layout of a module. Note that when you insert records using bulk-write the system ignores the custom layout-specific mandatory fields.
- To insert the records in a specific layout, you must specify the name of the custom layout in your CSV file. If left unspecified/incorrect value specified, the system inserts the records in the default layout in that module. Also, you must specify the relevant details in the field_mappings key in the input. Refer to sample input for more details.
- For field-types such as Date and Date/Time, there are default formats. For instance, for Date, the default format is MM/dd/yyyy, and for Date/Time, the default format is MM/dd/yyyy HH:mm:ss. If you specify the value for these fields in any other format in your CSV file, you must specify the format in your input. Refer to sample input for more details. Click here to know the allowed formats for Date, Date/Time, and Number fields.
Sample input to bulk-insert Subform data
Copied{
"operation": "insert",
"ignore_empty": true,
"callback": {
"url": "http://requestbin.fullcontact.com/1fcimk51",
"method": "post"
},
"resource": [
{
"type": "data",
"module": "Contact_Sub",//The API name of the subform in the Contacts module
"file_id": "111111000000451985",
"field_mappings": [
{
"api_name": "Parent_Id",//The CSV must contain the parent record ID of the contact
"find_by": "id",
"index": 3
},
{
"api_name": "Secondary Phone",
"index": 1
},
{
"api_name": "Secondary Email",
"index": 0
}
]
}
]
}
Sample input for bulk update
Copied{
"operation": "update",
"ignore_empty": true,
"callBack": {
"url": "http://requestbin.fullcontact.com/1bvgfh61",
"method": "post"
},
"resource": [
{
"type": "data",
"module": {
"api_name": "Contacts"
},
"find_by": "id",
"file_id": "111111000001492610",
"field_mappings": [
{
"api_name": "Layout",
"default_value": {
"value": "5725767000001022168" /*Specify the unique ID of the Custom Layout.
If this ID is not specified, the update will be applied to all layouts.*/
}
},
{
"api_name": "id",
"index": 1
},
{
"api_name": "Last_Name",
"index": 2
},
{
"api_name": "Account_Lookup",
"index": 3,
"find_by": "Account_Name"
}
]
}
]
}
Response Structure
- statusstring
Specifies the status of the API call. Sample - "status": "success".
- messagestring
Specifies the pre-defined comments for the job. Useful in case any errors occur.
- detailsJSON object
Contains the following details of the bulk write job.
- id(string) - Specifies the unique identifier of the bulk write job. Sample - "id": "111111000000541958".
- created_by(JSON object) - Specifies the ID and Name of the user who initiated the bulk write job. Sample - "created_by": { "id": "111111000000035795", "name": "Patricia Boyle" }.
Sample response
Copied{
"status": "success",
"code": "SUCCESS",
"message": "success",
"details": {
"id": "111111000000541958",
"created_by": {
"id": "111111000000035795",
"name": "Patricia Boyle "
}
}
}
Request JSON for parent-child modules
The parent module is the main module while subforms, line items, multi-select lookup fields and multi-user lookup fields are the children in the parent module. You must have individual CSV files for the parent and children.
- character_encodingString, optional
Represents the charset of the uploaded file. It is usually auto-detected, but if specified, then it will be used to read the file.
- operationString, mandatory
Represents the type of operation you want to perform on the bulk write job.
Values are
- insert - To create CSV records as new records in CRM.
- update - To update an existing record in CRM(This operation does not allow creation of new records).
- upsert - To update an existing record in CRM and create new records, if they do not exist already.
- ignore_emptyBoolean, optional
True - Ignores the empty values in a column and updates only the fields of a record without empty values
False or empty - The system updates records in CRM with empty values in the given file column.
The default value is false. - callbackJSON Object, optional
A valid URL that allows the HTTP POST method. The Bulk Write Job's details are posted to this URL on successful completion or failure of a job. Sample - "callback" : { "url": "https://sampledomain.com/getzohoresponse", "method": "post" }.
This JSON Object takes two keys—url and method.- url(string) - A valid URL, which should allow HTTP POST method. The Bulk Write Job's details are posted to this URL on successful completion or failure of a job.
- method(string) - The HTTP method of the callback url. The supported value is post.
- resourceJSON array, mandatory
A JSON array of objects containing the API names of the parent and children modules that you want to import, their field mappings, and the corresponding file IDs obtained from the Upload API. Note that the first object in this array must contain the details of the parent module. Note that when you want to bulk-write data to a parent module that has a multi-select lookup field, your first CSV file must contain the data of the parent module, and the second CSV file must contain the data of the linking module.
- type(string, mandatory) - Represents the type of module that you want to import. The value is data.
- module(JSON object, mandatory) - The API name of the module that you select for bulk write job.
For subforms or multi-user lookup, give their respective API names. For multi-select lookup, specify the API name of the linking module. - file_id(string, mandatory) - The file_id obtained from the file upload API. This ID must be the same for both the parent and child modules.
- file_names(JSON array, mandatory) - The name of the CSV file you have uploaded. This is to map the right CSV with the right module.
- find_by(string, mandatory for update and upsert, optional for insert) - The API name of a unique field or ID of a record. The system uses the value of this field to find the existing records in CRM. When you specify this parameter for insert operation, the system will skip the existing records from the file.
- field_mappings(JSON array, mandatory) - When the system processes a CSV file, the first row is treated as the header row. Each header name is treated as the field API name and data from a column are populated into the corresponding field represented by the API name. This parameter helps you to skip auto-mapping and define your own field mapping. Note that if you include this array in the input, data in the CSV will be mapped based only on the index value in this array.
- api_name(string, mandatory) - The API name of the field present in Zoho module object that you want to import. Refer Fields Meta Data API for the list of fields available in a module. An invalid field API name throws an error.
- parent_column_index(number, mandatory for the child object in the resource array) - This key helps to map the right parent record with the child record. For example, consider that your parent module is Leads and it has a subform. The parent CSV has the data of 500 records, and the subform CSV has the data of 500 subform records. Each of these subform records belongs to a specific lead. So, to map the right child with the right parent, you must use the "parent_column_index" key. To establish this, there must be a common column in both parent and the child.
For subforms and line items, it must be the "Parent_Id".
For multi-select lookup and multi-user lookup, it must be the API name of the parent lookup in the linking module.
For example, if you have the parent module as Leads which has a multi-select lookup to Contacts, then the linking module will be Leads vs Contacts. So, your parent CSV will be for Leads and the child CSV for the linking module. Here, to map the child with the parent, you must specify the parent_column_index for the lookup field of the parent in the linking module.
Refer to the Note section for more details. - index(number, optional) - The column index of the field you want to map to the CRM field. When you specify a non-existing index value, the system throws an error.
- find_by(string, mandatory for lookup fields) - The API name of the unique field in the module against which the system checks if there are existing records in CRM. You can also use id, API names of the system-defined unique fields, custom unique fields, lookup fields, and display columns/fields(the results displayed based on a field, that are listed when you search for an associated lookup. For example, Account Name is the display column when you have a look up in Contacts that points to Accounts.) as find_by fields. When you include parent_column_index, this key is not required.
- default_value(JSON object, optional) - Use this key if some of the records do not have a value in a column, and you want to replace it with a default value. Example: {"value": "Trade Show"}.
Notes
- The details of the parent must be the first object in the "resource" array.
- Each module can be mapped with only one CSV file.
- For subforms and line items, you can map any system-defined and custom fields.
- For multi-select lookup and multi-user lookup, you can only map the lookup fields in the linking module.
Sample Input
Copied{
"operation": "insert",
"ignore_empty": true,
"callback": {
"url": "https://entbf6cqr4sl.x.pipedream.net/",
"method": "post"
},
"resource": [
{
"type": "data",
"module": "Leads",
"file_id": "3652397000014524001",
"file_names": [
"bulk_write_leads.csv"
],
"field_mappings": [
{
"api_name": "Last_Name",
"index": 0
},
{
"api_name": "Company",
"index": 1
},
{
"api_name": "Email",
"find_by": "email",
"index": 2
},
{
"api_name": "User",
"find_by": "email",
"index": 3
}
]
},
{
"type": "data",
"module": "Secondary",
"file_id": "3652397000014524001",
"file_names": [
"bulk_write_subform.csv"
],
"field_mappings": [
{
"api_name": "Secondary_Email",
"index": 0
},
{
"api_name": "Secondary_Phone",
"index": 1
},
{
"api_name": "Parent_Id",
"parent_column_index": 0,
"index": 2
},
{
"type": "data",
"module": "Lead_Contact_Lookup",
"file_id": "425153000103247021",
"file_names": [
"LeadsMultiLookUp.csv"
],
"field_mappings": [
{
"api_name": "Leads",
"parent_column_index": 0,
"index": 0
},
{
"api_name": "Contacts",
"find_by": "id",
"index": 1
}
]
}
]
}
]
}
Response Structure
- statusstring
Specifies the status of the API call as "COMPLETED", "IN PROGRESS", "FAILED".
- resourceJSON array
Each object in this array represents the details of the job such as the module(parent and children, individually), field mappings, and the status pertaining to this CSV file.
- typestring
Contains the value "data" representing a data import.
- codestring
Represents the status of the data in this CSV file.
- fileJSON object
Represents the status of data import of this CSV file. It also contains the CSV file name, number of records present in the CSV, number of records added, skipped, and updated.
Possible Errors
- MANDATORY_FIELDS_NOT_MAPPED HTTP 400
All the mandatory fields in the module are not mapped.
Resolution: Map all the mandatory fields in the module. - MANDATORY_NOT_FOUND HTTP 400
Mandatory key or value is not specified in the request body. Example: "message": "Required key find_by is not available".
Resolution: Include the required key in the input. - INVALID_FIELD HTTP 400
The field API name is invalid.
Resolution: Specify the correct API name of the field. - INVALID_FORMAT HTTP 400
You have entered the date in the wrong format.
Resolution: Input the date in the correct format. - INVALID_FILE_ID HTTP 400
The file ID specified is invalid.
Resolution: Specify the correct file ID you received while uploading the CSV file. - HEADER_LIMIT_EXCEEDED HTTP 400
The number of fields mapped has exceeded the maximum limit of 200.
Resolution: You can only map up to 200 fields. - COLUMN_INDEX_NOT_FOUND HTTP 400
Index is mapped with negative values.
Resolution: "index" can only take positive integer values. - MODULE_NOT_AVAILABLE HTTP 400
The module name specified is invalid.
Resolution: The API name of the module is either wrong or this module is not supported for a bulk write job. Refer to the "Possible module name" section for the list of supported modules. - INVALID_URL_PATTERNHTTP 404
Please check if the URL trying to access is a correct one
Resolution: The request URL specified is incorrect. Specify a valid request URL. Refer to request URL section above. - OAUTH_SCOPE_MISMATCHHTTP 401
Unauthorized
Resolution: Client does not have ZohoCRM.bulk.CREATE. Create a new client with valid scope. Refer to scope section above. - NO_PERMISSIONHTTP 403
Permission denied to create
Resolution: The user does not have permission to create a bulk write job. Contact your system administrator. - INTERNAL_ERRORHTTP 500
Internal Server Error
Resolution: Unexpected and unhandled exception in Server. Contact support team. - INVALID_REQUEST_METHODHTTP 400
The http request method type is not a valid one
Resolution: You have specified an invalid HTTP method to access the API URL. Specify a valid request method. Refer to endpoints section above. - AUTHORIZATION_FAILEDHTTP 400
User does not have sufficient privilege to create.
Resolution: The user does not have the permission to create a bulk write job. Contact your system administrator.
Sample Response
Copied{
"status": "COMPLETED",
"resource": [
{
"status": "COMPLETED",
"module": "Leads",
"field_mappings": [
{
"api_name": "Last_Name",
"index": 0,
"format": null,
"find_by": null,
"module": null,
"parent_column_index": null,
"default_value": null
},
{
"api_name": "Company",
"index": 1,
"format": null,
"find_by": null,
"module": null,
"parent_column_index": null,
"default_value": null
},
{
"api_name": "Email",
"index": 2,
"format": null,
"find_by": "email",
"module": null,
"parent_column_index": null,
"default_value": null
},
{
"api_name": "User",
"index": 3,
"format": null,
"find_by": "email",
"module": null,
"parent_column_index": null,
"default_value": null
}
],
"type": "data",
"code": "COMPLETED",
"file": {
"status": "COMPLETED",
"name": "bulk_write_leads.csv",
"added_count": 100,
"skipped_count": 0,
"updated_count": 0,
"total_count": 100
}
},
{
"status": "COMPLETED",
"module": "Secondary",
"field_mappings": [
{
"api_name": "Secondary_Email",
"index": 0,
"format": null,
"find_by": null,
"module": null,
"parent_column_index": null,
"default_value": null
},
{
"api_name": "Secondary_Phone",
"index": 1,
"format": null,
"find_by": null,
"module": null,
"parent_column_index": null,
"default_value": null
},
{
"api_name": "Parent_Id",
"index": 3,
"format": null,
"find_by": null,
"module": null,
"parent_column_index": 0,
"default_value": null
}
],
"type": "data",
"code": "COMPLETED",
"file": {
"status": "COMPLETED",
"name": "bulk_write_subform.csv",
"added_count": 69,
"skipped_count": 0,
"updated_count": 0,
"total_count": 69
}
},
{
"status": "COMPLETED",
"module": "Lead_Contact_Lookup",
"field_mappings": [
{
"api_name": "Contacts",
"index": 1,
"format": null,
"find_by": "id",
"module": null,
"parent_column_index": null,
"default_value": null
},
{
"api_name": "Leads",
"index": 0,
"format": null,
"find_by": null,
"module": null,
"parent_column_index": null,
"default_value": null
}
],
"type": "data",
"code": "INPROGRESS",
"file": {
"status": "COMPLETED",
"name": "LeadsMultiLookUp.csv",
"added_count": 0,
"skipped_count": 10,
"updated_count": 0,
"total_count": 10
}
}
]
}