1

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"
    },
    "some@email.com": {
      "first_name": "New first name",
      "last_name": "New last name"
    },
    "some.other@email.com": {
      "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.

Jan
  • 11
  • 1

1 Answers1

0

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:

data = {
            "prospects":
                {"12234":
                     {"website": "https://www.google.com"},
                 "56789":
                     {"website": "https://www.google.com"}
                 }
        }

url = f'https://pi.pardot.com/api/prospect/version/3/do/batchUpsert?prospects={json.dumps(data)}&format=json'

response = requests.post(
           url,
           headers={
               "Authorization": f"Bearer {access_token}",
               "Pardot-Business-Unit-Id": business_unit_id})

print(response.text)

The result is correct:

{"@attributes":{"stat":"ok","version":1},"errors":{}}

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.

Jan
  • 11
  • 1
  • For those who come across this, this answer is not accurate. While possible to send the JSON data in the URL as the answer demonstrates, it is best practice to POST it to Pardot. Be sure to use content type of x-www-form-urlencoded, with the value "prospects" containing the JSON string. – Adam Erstelle Feb 01 '23 at 19:07
  • Pardot confirmed the problem in a case I opened. There seems to be a problem with the JSON parser in some cases. No matter of the content type. This was the first point where I tried to fix the problem. – Jan Feb 02 '23 at 20:18