I'm trying to use Salesforce's bulk API to run a query on some CSV data. Here is the desired result:

In SF, we have a field product.serial__c. I have a CSV with a bunch of serial numbers that I would like to pull other fields from, i.e.

SELECT product.name, product.price__c FROM product where product.serial__c IN (serial_csv) 

So I'd like to add a batch, filled with this CSV data and run a query with it.

My question is how the add batch API call should be. Here is my function in python:

#code based on http://www.wadewegner.com/2014/04/update-records-with-python-and-the-salesforce-bulk-api/

def addBatch(instance, session_id, job_id, objects):

    request = u"""<?xml version="1.0" encoding="UTF-8"?>
                <sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload">
                    """ + objects + """

    url = "https://" + instance + ".salesforce.com/services/async/32.0/job/" + job_id + "/batch"
    headers = {"X-SFDC-Session": session_id, "Content-Type": "text/csv; charset=UTF-8"}

    response = requests.post(url = url, headers = headers, data = request, verify = False)
    return unicode(response.text)

Currently, I'm placing all my csv data in the objects parameter, i.e.:

csv_data = "0000,0001,0002,0003,0004,...,1111"
response = addBatch(instance, session_id, job_id, csv_data)

Is this incorrect?

Where do I put the query? All the docs on SF seem to point that I would put it in the 'objects' parameter in my function. Then where would my csv data go?

I'm sure I've completely confused how to use this API...

  • Did you find answer to your problem? Can you share your solution? thanks.
    – user20755
    May 25, 2015 at 15:41
  • Yes I did. Salesforce actually makes developing your own API really easy. You still authorize via SOAP, but then you can design your own apex class with a method like "doPost(data)". You can then handle it how you may and return the results. Very simple.
    – ZAR
    May 25, 2015 at 18:43
  • Here is the doc: developer.salesforce.com/page/…
    – ZAR
    May 25, 2015 at 18:44

1 Answer 1


While not exactly what I was looking for, Salesforce makes it really simple to design your own REST API with an apex class. You still use their SOAP API to gain credentials, but then you're free to tailor your own API. I was able to create an API that handled the payload (the CSV) and called another apex class to run my query and then simply returned the results. Very, very simple.

Here are the SF docs regarding building a REST API with apex:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .