Note: Pardot's API is in XML - however chaining only supports JSON. This means that for individual calls you'll receive back mock XML, but for the chain it will be formatted in JSON.
In this example we will be making a Pardot request to either update or insert a new user. This will require just three calls, but the calls will be conditional based on responses. This means that traditionally we would need to first make a call to see if the user exists, perform logic on that call, and then perform the secondary call like so:
However, using a chain, we can make all the calls with a single HTTP POST Request like so:
http://api-multi-request.demos.mikestowe.com/pardot/api/multirequest
[{
"doOn": "always",
"href": "/login/version/4/",
"method": "post",
"data": {
"email": "admin@mycompany.net",
"password": "myPassword",
"user_key": "1234567890"
},
"globals": {
"api_key": "body.api_key"
},
"return": ["api_key"]
},
{
"doOn": "200",
"href": "/prospect/version/4/do/read/email/email@mycompany.net?api_key=${global.api_key}&user_key=1234567890",
"method": "get",
"data": {},
"return": ["id"]
},
[
[{
"doOn": "200",
"href": "/prospect/version/4/do/update/id/${body.id}?api_key=${global.api_key}&user_key=1234567890",
"method": "get",
"data": {},
"return": true
}],
[{
"doOn": "400",
"href": "/prospect/version/4/do/create/email/email@mycompany.net?api_key=${global.api_key}&user_key=1234567890",
"method": "get",
"data": {},
"return": true
}]
]
]
Or to test the flow for a user that doesn't exist:
http://api-multi-request.demos.mikestowe.com/pardot/api/multirequest
[{
"doOn": "always",
"href": "/login/version/4/",
"method": "post",
"data": {
"email": "admin@mycompany.net",
"password": "myPassword",
"user_key": "1234567890"
},
"globals": {
"api_key": "body.api_key"
},
"return": ["api_key"]
},
{
"doOn": "200",
"href": "/prospect/version/4/do/read/email/fake@mycompany.net?api_key=${global.api_key}&user_key=1234567890",
"method": "get",
"data": {},
"return": ["id"]
},
[
[{
"doOn": "200",
"href": "/prospect/version/4/do/update/id/${body.id}?api_key=${global.api_key}&user_key=1234567890",
"method": "get",
"data": {},
"return": true
}],
[{
"doOn": "400",
"href": "/prospect/version/4/do/create/email/fake@mycompany.net?api_key=${global.api_key}&user_key=1234567890",
"method": "get",
"data": {},
"return": true
}]
]
]