Can I get some help, I'm having trouble getting Bulk V2 API to accept csv data:
Below is the final portions of my script (python):
1. I successfully login and authenticate (so have the instance_url)
2. Then, I compile/gather csv data: csv_data = df.to_csv(index=False) #-- from a pandas dataframe
--------------------------------------------------------------------------
From here, this is what is run:
--------------------------------------------------------------------------
bulk_api_v2_url = f"{instance_url}/services/data/v62.0/jobs/ingest/"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
}
# Create a job
job_data = {
"object": "Account",
"operation": "update",
"contentType": "CSV",
}
response = requests.post(bulk_api_v2_url, headers=headers, json=job_data)
job_id = response.json()["id"]
upload_url = f"{instance_url}/services/data/v62.0/jobs/ingest/{job_id}/batches/"
files = {"file": ("data.csv", csv_data)}
response = requests.put(upload_url, headers=headers, files=files)
--------------------------------------------------------------------------
Here is a typical response:
--------------------------------------------------------------------------
[{'errorCode': 'BULK_API_ERROR', 'message': 'Wrong content-type for batch (application/json), job is of type: text/csv'}]
I also tried this, with the same message:
response = requests.put(upload_url, data=csv_data, headers=headers)
--------------------------------------------------------------------------
1. I have tried adjusting the header "Content-Type" to "text/csv" - but this fails, even in Postman
2. Also tried converting the job-data to json, but the API doesn't seem to support this:
-
https://salesforce.stackexchange.com/questions/234791/does-salesforce-bulk-api-2-0-accept-json-as-the-contenttype
Is there a way to adjust the content type of the batch?
Other suggestions?
Thanks ahead of time...
Jarrell
ok figured this out, on my own: my headers were incorrect - so I used this:
headers2 = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "text/csv",
}
response = requests.put(upload_url, data=csv_data, headers=headers2)