Your use case. Our milestone. The 200th post in our "Kaizen Series: Continuous Improvement for Developer Experience" is coming up. Share Now

X
Skip to product menu
close
  • Recent Launches
    Press Space or Enter to display list of options
EXPLORE ALL PRODUCTS

Recent Launches

New

Easy domain registration, transfer, and secured DNS management.

Try now
New

Payroll software with automated tax payments and filing.

Try now
New

Low-code IoT platform and solutions for connected businesses.

Try now
New

Business formation service to launch and grow your businesses.

Try now
New

Unified payment solution built for all businesses.

Try now
New

Comprehensive email security and archiving for every business.

Try now
Suites

Cloud-based qualitative data analysis tool.

Try now
New

Online community platform for individuals and businesses to grow their network and brand.

Try now
New

Modern retail POS to sell better, manage your entire business, and join the digital revolution.

Try now
SuitesNew

Unified project management platform for intelligent, data-driven work.

Try now
Suites

Unified platform for customer service and support teams.

Try now

Sales

CRM

Comprehensive CRM platform for customer-facing teams.

CRM
Voice

Cloud Contact Center Software for businesses.

Voice
Sign

Digital signature app for businesses.

Sign
Forms

Build online forms for every business need.

Forms
Bigin

Simple CRM for small businesses moving from spreadsheets.

Bigin
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
Bookings

Appointment scheduling app for consultations with customers.

Bookings
RouteIQ

Comprehensive sales map visualization and optimal route planning solution.

RouteIQ
Thrive

Complete loyalty and affiliate management platform.

Thrive
Suites
CRM Plus

Unified platform to deliver top-notch customer experience.

CRM Plus

Marketing

Campaigns

Create, send, and track targeted email campaigns that drive sales.

Campaigns
Voice

Cloud Contact Center Software for businesses.

Voice
Sign

Digital signature app for businesses.

Sign
Forms

Build online forms for every business need.

Forms
Social

All-in-one social media management software.

Social
Survey

Design surveys to reach and interact with your audience.

Survey
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
Sites

Online website builder with extensive customisation options.

Sites
Backstage

End-to-end event management software.

Backstage
PageSense

Website conversion optimization and personalisation platform.

PageSense
Marketing Automation

All-in-one marketing automation software.

Marketing Automation
LandingPage

Smart landing page builder to increase conversion rates

LandingPage
Webinar

Webinar platform for webcasting online webinars.

Webinar
NEW
LeadChain

Sync, manage, and convert leads across channels seamlessly.

LeadChain
NEW
Domains

Easy domain registration, transfer, and secured DNS management.

Domains
NEW
CommunitySpaces

Online community platform for individuals and businesses to grow their network and brand.

CommunitySpaces
Thrive

Complete loyalty and affiliate management platform.

Thrive
Publish

Manage all your local business listings on a single platform.

Publish
Suites
Marketing Plus

Unified marketing platform for marketing teams.

Marketing Plus

Commerce and POS

Commerce

eCommerce platform to manage and market your online store.

Commerce

Service

Desk

Helpdesk software to deliver great customer support.

Desk
Assist

Remote support and unattended remote access software.

Assist
Voice

Cloud Contact Center Software for businesses.

Voice
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
Bookings

Appointment scheduling app for consultations with customers.

Bookings
FSM

End-to-end field service management platform for service businesses.

FSM
Lens

Interactive remote assistance software with augmented reality.

Lens
Solo

The all-in-one toolkit for solopreneurs.

Solo
Suites
Service Plus

Unified platform for customer service and support teams.

Service Plus

Finance

Books

Powerful accounting platform for growing businesses.

Books
Expense

Effortless expense reporting platform.

Expense
Sign

Digital signature app for businesses.

Sign
Inventory

Powerful stock management and inventory control software.

Inventory
FREE
Invoice

100% Free invoicing solution.

Invoice
Billing

End-to-end billing solution for your business.

Billing
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
Commerce

eCommerce platform to manage and market your online store.

Commerce
Checkout

Collect payments online with custom branded pages.

Checkout
Practice

Practice management software for accounting firms.

Practice
Solo

The all-in-one toolkit for solopreneurs.

Solo
NEW
Payments

Unified payment solution built for all businesses.

Payments
Suites
Finance Plus

All-in-one suite to manage your operations and finances.

Finance Plus

Email, Storage, and Collaboration

Mail

Secure email service for teams of all sizes.

Mail
Voice

Cloud Contact Center Software for businesses.

Voice
Sign

Digital signature app for businesses.

Sign
WorkDrive

Online file management for teams.

WorkDrive
Bookings

Appointment scheduling app for consultations with customers.

Bookings
Cliq

Stay in touch with teams no matter where you are.

Cliq
Notebook

Beautiful home for all your notes.

Notebook
Meeting

Online meeting software for all your video conferencing & webinar needs.

Meeting
Connect

Employee experience platform to communicate, engage, and build positive employee relations.

Connect
Learn

Knowledge and learning management platform.

Learn
Office Integrator

Built in document editors for web apps.

Office Integrator
Writer

Word processor for focused writing and discussions.

Writer
TeamInbox

Shared inboxes for teams.

TeamInbox
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
Show

Create, edit, and share slides with a sleek presentation app.

Show
Tables

Work management tool to connect people, processes, and information.

Tables
Sheet

Spreadsheet software for collaborative teams.

Sheet
Office Suite

Powerful collaborative work platform for teams.

Office Suite
Calendar

Online business calendar to manage events and schedule appointments.

Calendar
ToDo

Collaborative task management for individuals and teams.

ToDo
FREE
PDF Editor

Collaborative online PDF editing tool.

PDF Editor
Suites
Workplace

Application suite built to improve team productivity and collaboration.

Workplace

Human Resources

Expense

Effortless expense reporting platform.

Expense
Recruit

Intuitive recruiting platform built to provide hiring solutions.

Recruit
People

Organize, automate, and simplify your HR processes.

People
Sign

Digital signature app for businesses.

Sign
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
Shifts

Employee scheduling and time tracking app.

Shifts
Workerly

Manage temporary staffing with an employee scheduling solution.

Workerly
Suites
People Plus

Comprehensive HR platform for seamless employee experiences.

People Plus

Security and IT Management

Creator

Build custom apps to simplify business processes.

Creator
Assist

Remote support and unattended remote access software.

Assist
Vault

Online password manager for teams.

Vault
Directory

Workforce identity and access management solution for cloud businesses.

Directory
Lens

Interactive remote assistance software with augmented reality.

Lens
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA
NEW
eProtect

Comprehensive email security and archiving for every business.

eProtect
FREE
OneAuth

Secure multi-factor authenticator (MFA) for all your online accounts.

OneAuth
Toolkit

Complete resource for any admin-related lookup queries.

Toolkit

BI and Analytics

Analytics

Modern self-service BI and analytics platform.

Analytics
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep
NEW
IoT

Harnessing IoT analytics for real-time operational intelligence.

IoT
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI

Project Management

Projects

Manage, track, and collaborate on projects with teams.

Projects
Sprints

Planning and tracking tool for scrum teams.

Sprints
BugTracker

Automatic bug tracking software for managing bugs.

BugTracker
Solo

The all-in-one toolkit for solopreneurs.

Solo
Suites
Projects Plus

Unified project management platform for intelligent, data-driven work.

Projects Plus

Developer Platforms

Creator

Build custom apps to simplify business processes.

Creator
Flow

Automate business workflows by creating smart integrations.

Flow
Office Integrator

Built in document editors for web apps.

Office Integrator
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
Tables

Work management tool to connect people, processes, and information.

Tables
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA
NEW
IoT

Build, deploy, and scale IoT solutions for connected businesses.

IoT
Apptics

Application analytics for all apps.

Apptics
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI

IoT

NEW
IoT

Low-code IoT platform and solutions for connected businesses.

IoT

Search Result

CRM Plus

Unified platform to deliver top-notch customer experience.

Try now
CRM Plus
Service Plus

Unified platform for customer service and support teams.

Try now
Service Plus
Finance Plus

All-in-one suite to manage your operations and finances.

Try now
Finance Plus
People Plus

Comprehensive HR platform for seamless employee experiences.

Try now
People Plus
Workplace

Application suite built to improve team productivity and collaboration.

Try now
Workplace
Marketing Plus

Unified marketing platform for marketing teams.

Try now
Marketing Plus
Projects Plus

Unified project management platform for intelligent, data-driven work.

Try now
Projects Plus
All-in-one suite

Zoho One

The Operating System for Business

Run your entire business on Zoho with our unified cloud software, designed to help you break down silos between departments and increase organizational efficiency.

TRY ZOHO ONE
Zoho Marketplace

With over 2000 ready-to-use extensions across 40+ categories, connect your favorite business tools with the Zoho products you already use.

EXPLORE MARKETPLACE
Skip to main content

Python SDK Samples - Bulk Write Operations

Upload File
Create a Bulk Write Job
              
              
import os
from zcrmsdk.src.com.zoho.crm.api.bulk_write import *
from zcrmsdk.src.com.zoho.crm.api.util import Choice, StreamWrapper
from zcrmsdk.src.com.zoho.crm.api import HeaderMap
class BulkWrite(object):
    @staticmethod
    def create_bulk_write_job(module_api_name, file_id):

        """
        This method is used to create bulk write job with the uploaded file ID
        :param module_api_name: The API Name of the module.
        :param file_id: The ID of the uploaded file to create BulkWrite Job.
        """

        # 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)

        if response is not None:
            # Get the status code from response
            print('Status Code: ' + str(response.get_status_code()))

            # Get object from response
            response_object = response.get_object()

            if response_object is not None:

                # Check if expected SuccessResponse instance is received.
                if isinstance(response_object, SuccessResponse):

                    # Get the Status
                    print("Status: " + response_object.get_status().get_value())

                    # Get the Code
                    print("Code: " + response_object.get_code().get_value())

                    print("Details")

                    # Get the details dict
                    details = response_object.get_details()

                    for key, value in details.items():
                        print(key + ' : ' + str(value))

                    # Get the Message
                    print("Message: " + response_object.get_message().get_value())

                # Check if the request returned an exception
                elif isinstance(response_object, APIException):
                    # Get the Status
                    print("Status: " + response_object.get_status().get_value())

                    # Get the Code
                    print("Code: " + response_object.get_code().get_value())

                    print("Details")

                    # Get the details dict
                    details = response_object.get_details()

                    for key, value in details.items():
                        print(key + ' : ' + str(value))

                    # Get the Message
                    print("Message: " + response_object.get_message().get_value())
 
Get Bulk Write Job Details
              
              
import os
from zcrmsdk.src.com.zoho.crm.api.bulk_write import *
from zcrmsdk.src.com.zoho.crm.api.util import Choice, StreamWrapper
from zcrmsdk.src.com.zoho.crm.api import HeaderMap
class BulkWrite(object):
    @staticmethod
    def get_bulk_write_job_details(job_id):

        """
        This method is used to get the details of a bulk write job performed previously.
        :param job_id: The unique ID of the bulk write job.
        """

        """
        example
        job_id = 3477061000005615003
        """

        # Get instance of BulkWriteOperations Class
        bulk_write_operations = BulkWriteOperations()

        # Call get_bulk_write_job_details method that takes job_id as parameter
        response = bulk_write_operations.get_bulk_write_job_details(job_id)

        if response is not None:

            # Get the status code from response
            print('Status Code: ' + str(response.get_status_code()))

            if response.get_status_code() in [204, 304]:
                print('No Content' if response.get_status_code() == 204 else 'Not Modified')
                return

            # Get object from response
            response_object = response.get_object()

            if response_object is not None:

                # Check if expected BulkWriteResponse instance is received
                if isinstance(response_object, BulkWriteResponse):

                    # Get the Job Status of the bulkWriteResponse
                    print("Bulk write Job Status: " + response_object.get_status())

                    # Get the CharacterEncoding of the bulkWriteResponse
                    print("Bulk write CharacterEncoding: " + response_object.get_character_encoding())

                    resources = response_object.get_resource()

                    if resources is not None:
                        for resource in resources:
                            # Get the Status of each Resource
                            print("Bulk write Resource Status: " + resource.get_status().get_value())

                            # Get the Type of each Resource
                            print("Bulk write Resource Type: " + resource.get_type().get_value())

                            # Get the Module of each Resource
                            print("Bulk write Resource Module: " + resource.get_module())

                            # Get the field mappings
                            field_mappings = resource.get_field_mappings()

                            if field_mappings is not None:
                                for field_mapping in field_mappings:
                                    # Get the APIName of each FieldMapping
                                    print("Bulk write Resource FieldMapping Module: " + field_mapping.get_api_name())

                                    if field_mapping.get_index() is not None:
                                        # Get the Index of each FieldMapping
                                        print("Bulk write Resource FieldMapping Index: " + str(field_mapping.get_index()))

                                    if field_mapping.get_format() is not None:
                                        # Get the Format of each FieldMapping
                                        print("Bulk write Resource FieldMapping Format: " + field_mapping.get_format())

                                    if field_mapping.get_find_by() is not None:
                                        # Get the FindBy of each FieldMapping
                                        print("Bulk write Resource FieldMapping FindBy: " + field_mapping.get_find_by())

                                    if field_mapping.get_default_value() is not None:
                                        print('Default values')

                                        for key, value in field_mapping.get_default_value().items():
                                            print(key + ": " + str(value))

                            # Get the file
                            file = resource.get_file()

                            if file is not None:
                                # Get the Status of the File
                                print("Bulk write Resource File Status: " + file.get_status().get_value())

                                # Get the Name of the File
                                print("Bulk write Resource File Name: " + file.get_name())

                                # Get the AddedCount of the File
                                print("Bulk write Resource File AddedCount: " + str(file.get_added_count()))

                                # Get the SkippedCount of the File
                                print("Bulk write Resource File SkippedCount: " + str(file.get_skipped_count()))

                                # Get the UpdatedCount of the File
                                print("Bulk write Resource File UpdatedCount: " + str(file.get_updated_count()))

                                # Get the TotalCount of the File
                                print("Bulk write Resource File TotalCount: " + str(file.get_total_count()))

                    callback = response_object.get_callback()

                    if callback is not None:
                        # Get the CallBack Url
                        print("Bulk write CallBack Url: " + callback.get_url())

                        # Get the CallBack Method
                        print("Bulk write CallBack Method: " + callback.get_method())

                    # Get the ID of the BulkWriteResponse
                    print("Bulk write ID: " + str(response_object.get_id()))

                    result = response_object.get_result()

                    if result is not None:
                        # Get the DownloadUrl of the Result
                        print("Bulk write DownloadUrl: " + result.get_download_url())

                    # Get the CreatedBy User instance of the BulkWriteResponse
                    created_by = response_object.get_created_by()

                    # Check if created_by is not None
                    if created_by is not None:
                        # Get the Name of the created_by User
                        print("Bulkwrite Created By - Name: " + created_by.get_name())

                        # Get the ID of the created_by User
                        print("Bulkwrite Created By - ID: " + created_by.get_id())

                    # Get the Operation of the BulkWriteResponse
                    print("Bulk write Operation: " + response_object.get_operation())

                    # Get the CreatedTime of the BulkWriteResponse
                    print("Bulk write File CreatedTime: " + str(response_object.get_created_time()))

                # Check if the request returned an exception
                elif isinstance(response_object, APIException):
                    # Get the Status
                    print("Status: " + response_object.get_status().get_value())

                    # Get the Code
                    print("Code: " + response_object.get_code().get_value())

                    print("Details")

                    # Get the details dict
                    details = response_object.get_details()

                    for key, value in details.items():
                        print(key + ' : ' + str(value))

                    # Get the Message
                    print("Message: " + response_object.get_message().get_value())
 
Download Result
              
              
import os
from zcrmsdk.src.com.zoho.crm.api.bulk_write import *
from zcrmsdk.src.com.zoho.crm.api.util import Choice, StreamWrapper
from zcrmsdk.src.com.zoho.crm.api import HeaderMap
class BulkWrite(object):
    @staticmethod
    def download_bulk_write_result(download_url, destination_folder):

        """
        This method is used to download the result of bulk write job.
        :param download_url: The URL present in the download_url key in the response of Get Bulk Write Job Details.
        :param destination_folder: The absolute path where downloaded file has to be stored.
        """

        """
        example
        download_url = "https://download-accl.zoho.com/v2/crm/6735/bulk-write/347706122009/347706122009.zip"
        destination_folder = "/Users/user_name/Documents"
        """

        # Get instance of BulkWriteOperations Class
        bulk_write_operations = BulkWriteOperations()

        # Call download_bulk_write_result method that takes download_url as parameter
        response = bulk_write_operations.download_bulk_write_result(download_url)

        if response is not None:

            # Get the status code from response
            print('Status Code: ' + str(response.get_status_code()))

            if response.get_status_code() in [204, 304]:
                print('No Content' if response.get_status_code() == 204 else 'Not Modified')
                return

            # Get object from response
            response_object = response.get_object()

            if response_object is not None:

                # Check if expected FileBodyWrapper instance is received.
                if isinstance(response_object, FileBodyWrapper):

                    # Get StreamWrapper instance from the returned FileBodyWrapper instance
                    stream_wrapper = response_object.get_file()

                    # Construct the file name by joining the destination_folder and the name from StreamWrapper instance
                    file_name = os.path.join(destination_folder, stream_wrapper.get_name())

                    # Open the destination file where the file needs to be written in 'wb' mode
                    with open(file_name, 'wb') as f:
                        # Get the stream from StreamWrapper instance
                        for chunk in stream_wrapper.get_stream():
                            f.write(chunk)

                        f.close()

                # Check if the request returned an exception
                elif isinstance(response_object, APIException):
                    # Get the Status
                    print("Status: " + response_object.get_status().get_value())

                    # Get the Code
                    print("Code: " + response_object.get_code().get_value())

                    print("Details")

                    # Get the details dict
                    details = response_object.get_details()

                    for key, value in details.items():
                        print(key + ' : ' + str(value))

                    # Get the Message
                    print("Message: " + response_object.get_message().get_value())