function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to INSERT / UPDATE a large number of records (efficiently) with REST API?

The "Getting Started" code examples show how to INSERT and UPDATE individual records using the new REST API.


In my own testing, this seems to take about 100 msec per REST API call.


If I need to INSERT or UPDATE 1,000 records, and I do then one-by-one, that's going to take a long time.


Can anyone point to some documentation or example code, that shows how to many records with a single REST API call?


thanks in advance,

  David Jones, PhD



Thanks for the answer Simon.


I consider this a "workaround", rather than a proper solution.


I have used the "SOAP" API to do a bulk update to Salesforce before, so I realized it can be done.


However, it seems inelegant to mix-and-match the REST API and SOAP API.


Are there any plans to add the ability to insert / update more than one row at a time using the REST API?

The syntax would be different from the single row updates, ... but the JSON payload could certainly handle multiple rows.



  David Jones




The Bulk API is REST based, its not the SOAP API


Hi Simon,


Perhaps you can clarify, ... the documentation at the link you gave (below) seems clearly to be describing a SOAP API:


In the left column on this documenation page, Step 1 is:


Step 1: Logging In Using the SOAP Web Services API


On that page, it says:


"The Bulk API does not provide a login operation, so you must use the SOAP Web services API to log in."


Note, this is different from the OAuth2 authentication used by the SF REST API.


The example code makes reference to SOAP:


 curl -H "Content-Type: text/xml; charset=UTF-8" -H "SOAPAction: login" -d @login.txt

You need a sessionId, you can get one using the soap login, oauth, merge fields, etc.


So, ... is there any documentation for how to use JSON (as part of the new REST API) to perform Bulk updates, once authenticated?


I don't see anything that is different from the old SOAP API.



  David Jones



It doesn't yet support json, you can use xml or csv for the payload.


Since the SF REST API is still in "preview", is there a possibility to add the functionality to INSERT / UPDATE several rows at a time using JSON?  It would be great to be able to do everything under the same REST API paradigm.


The existing Bulk API using SOAP is a completely different beast.


-- David



You're looking at the wrong thing, the Bulk API is REST based, its not SOAP based, please see


That is the URL I was looking at.

Perhaps it is just the wording in some parts of the documentation that is wrong:


In various places, it talks about "SOAP Web services":


Do these pages need to be updated for the REST API?


- - - - -

Under the heading "Request Basics > About URIs", it says:


You send HTTP requests to a URI to perform operations with the Bulk API.

The URI where you send HTTP requests has the following format:



- - - - -

Under the heading "Request Basics > Setting a Session Handler", it says:


All HTTP requests must contain a valid API session ID obtained with the SOAP Web services APIlogin() call.

The session ID is returned in the SessionHeader.

The following example shows how to specify the required information once you have obtained it from the login()



POST /service/async/20.0/job/ HTTP/1.1
Content-Type: application/xml; charset=UTF-8
Accept: application/xml
User-Agent: Salesforce Web Service Connector For Java/1.0
X-SFDC-Session: sessionId
Connection: keep-alive
Content-Length: 135

<?xml version="1.0" encoding="UTF-8"?>

The docs could be clearer (they were written before the rest api and ouath impl's existed).


As i said earlier you need a sessionId, it doesn't care where you get one from, use soap login, use oAuth, use a merge field in the UI.


The other thing is just a convoluted way to say which instance you're on, there's nothing soap specific about it.

Mysti, Developer DocumentationMysti, Developer Documentation

Thank you for highlighting these issues with the documentation, we'll definitely address them.


This topic explains the different API offerings:


This topic will be updated with information about REST API for GA in all the API documentation.

BI Dev 9BI Dev 9
I am trying to update some Leads with the bulk api. but although it's looks like it works it didn't do nothing. Can someone please tell me if i do something wrong? Attached my code: (id is the Lead id in Salesforce. I write hard coded dict just for test)

bulk = SalesforceBulk(sessionId=sf.session_id, host=sf.sf_instance)
ob = bulk.create_update_job("Lead", contentType='CSV', concurrency='Parallel') 
disbursals = [{'id': '00Qb000000RQWUE','Pro_User_Type__c':'Demo','Last_Pro_Visit_Date__c':1489984909000}]
csv_iter = CsvDictsAdapter(iter(disbursals))
batch = bulk.post_bulk_batch(job, csv_iter)
bulk.wait_for_batch(job, batch)

Thanks a lot !!