Download Bulk Write Result
Purpose
To download the result of the bulk write job as a CSV file.
Download URL
Use the URL present in the download_url parameter in the response of Get Bulk Write Job Details.
The file will be in the .zip format. Extract it to get the CSV file. The filename would be in the modulename-filename format. Example: Deals-bulkwrite.
The CSV file will contain the first three mapped columns from the uploaded file, and three more columns — ID, Status, and Errors.
- STATUS
This column indicates if the record is added, skipped, updated, or unprocessed.
- RECORD_ID
This column indicates the added or updated record's ID in Zoho CRM.
- ERRORS
This column contains the error code. The format is:
<errorCode>-<column_header> for a single error. Example: MANDATORY_NOT_FOUND-Company
<errorCode>-<column_header>:<errorCode>-<column_header> for multiple errors. Example: MANDATORY_NOT_FOUND-Company,Last_Name:DUPLICATE_DATA-Email
The possible errors are MANDATORY_NOT_FOUND, INVALID_DATA, DUPLICATE_DATA, NOT_APPROVED, BLOCKED_RECORD, CANNOT_PROCESS, LIMIT_EXCEEDED, and RESOURCE_NOT_FOUND.
Sample Result
Copied//Get instance of BulkWriteOperations Class
$bulkWriteOperations = new BulkWriteOperations();
//Call downloadBulkWriteResult method that takes downloadUrl as parameters
$response = $bulkWriteOperations->downloadBulkWriteResult($downloadUrl);
Copied<?php
class DownloadBulkWriteResult{
public function execute(){
$curl_pointer = curl_init();
$curl_options = array();
$curl_options[CURLOPT_URL] = "https://download-accl.zoho.com/v2.1/crm/673573045/bulk-write/3477061000007780026/3477061000007780026.zip";
$curl_options[CURLOPT_RETURNTRANSFER] = true;
$curl_options[CURLOPT_HEADER] = 1;
$curl_options[CURLOPT_CUSTOMREQUEST] = "GET";
$headersArray = array();
$headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " ."1000.bb7XXXXXXXXX96e043dcfbb.5eXXXXXXXXX3786437c8d9f536e";
$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);
}
}
$response = $content;
if ($response == null && $responseInfo['http_code'] != 204) {
list ($headers, $content) = explode("\r\n\r\n", $content, 2);
$response = json_decode($content, true);
}
$contentDisp = $headerMap['Content-Disposition'];
$fileName = substr($contentDisp, strrpos($contentDisp, "'") + 1, strlen($contentDisp));
if (strpos($fileName, "=") !== false)
{
$fileName = substr($fileName, strrpos($fileName, "=") + 1, strlen($fileName));
$fileName = str_replace(array(
'\'',
'"'
), '', $fileName);
}
$filePath = "/Users/test/PHP/PHPNativeSampleCode/";
$fp = fopen($filePath . $fileName, "w"); // $filePath - absolute path where downloaded file has to be stored.
$stream = $response;
fputs($fp, $stream);
fclose($fp);
}
}
(new DownloadBulkWriteResult())->execute();
Copied# Get instance of BulkWriteOperations Class
bwo = BulkWrite::BulkWriteOperations.new
# Call download_bulk_write_result method that takes download_url as parameter
response = bwo.download_bulk_write_result(download_url)
Copiedrequire 'net/http'
require 'json'
class DownloadBulkWriteResult
def execute
url = "https://download-accl.zoho.com/v2.1/crm/673573045/bulk-write/3477061000007780026/3477061000007780026.zip"
url = URI(url)
req = Net::HTTP::Get.new(url.request_uri)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
headers={}
headers["Authorization"]="Zoho-oauthtoken 1000.dfa7XXXXXXXXXXXXXXXXXX84f9665840.c176aeXXXXXXXXXXXX13f3d37a84d"
headers&.each { |key, value| req.add_field(key, value) }
response=http.request(req)
file_name = response.to_hash["content-disposition"][0].split('=')[1]
file_name = file_name.split("''")[1] if file_name.include? "''"
file_name = file_name.gsub('"', '') if file_name.include? '"'
status_code = response.code.to_i
headers = response.each_header.to_h
print status_code
print headers
unless response.body.nil?
File.open("/Users/test/RUBY/RUBYNativeSampleCode/"+file_name, 'w') { |file| file.write(response.body) }
end
end
end
DownloadBulkWriteResult.new.execute