Skip to main content
Zachariah Rosenberg 님이 #Integration에 질문했습니다
Hello,

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 thanks to 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 + """

</sObjects>"""

⌗encoded_request = request.encode('utf-8')

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...

Thank you all!

Best,

Zac
답변 1개
0/9000