I want to batchUpsert data into Pardot by using the Pardot API 3. Single upserts work fine. Since I have a lot of data to upsert I want to use the /api/prospect/version/3/do/batchUpsert endpoint.
When I use the following code using Python3 I get a strange result I can't solve. Maybe someone knows the solution for that:
data = {"prospects": {"12345": {"website": "https://www.abcd.com"}}}
endpoint = "https://pi.pardot.com/api/prospect/version/3/do/batchUpsert"
response = requests.post(
endpoint,
headers={
"Authorization": f"Bearer {access_token}",
"Pardot-Business-Unit-Id: business_unit_id
},
json=data
}
I replaces json with data and params, that doen't matter for my problem. I receive the following error message:
{"@attributes":{"stat":"fail","version":1,"err_code":71},"err":"Input needs to be valid JSON or XML"}
The Pardot API documentation tells me to use the following syntax for a batchUpsert:
{
"prospects": {
"1234": {
"first_name": "New first name",
"last_name": "New last name"
},
"[email protected]": {
"first_name": "New first name",
"last_name": "New last name"
},
"[email protected]": {
"first_name": "New first name",
"last_name": "New last name"
}
}
}
I'm completely lost! Maybe someone can help?
Thanks in advance!
I tried to batchUpsert data into the pardot API 3 using Python3. I expected to see an update in the webinterface for my test prospect.
With some help of the Pardot dev team it came out they struggle with the same error using application/json and transfering the data raw. Here is the solution how to trigger a batchUpsert request using python:
The result is correct:
The problem is the JSON data HAVE to be in the URL. Transmitting it in the request.post under json, data or params will not work!
I hope this post will save other devs some time.