1
votes

I'm using GuzzleHttp to send requests to Pardots API.

class PardotIntegration {

    private $client;

    private $apikey;



    public function __construct() {
        $this->client  = new \GuzzleHttp\Client();
    }

    public function authenticate() {
        $params = [
            'email' => '[email protected]',
            'user_key'   => '3487328947239478927',
            'password' => 'password'
        ];

        $res = $this->client->post('https://pi.pardot.com/api/login/version/3', [

            'form_params' => $params
        ]);

        echo $res->getBody();


    }


}

$pardot = new PardotIntegration;

$pardot->authenticate();

The documentation states you can return either XML or JSON from a request: http://developer.pardot.com/#changing-the-api-response-format

However, I don't know how to return JSON instead of XML which is the default.

I've tried adding

$res = $this->client->post('https://pi.pardot.com/api/login/version/3', [
            'headers' => [
                'Accept' => 'application/json'
            ],
            'form_params' => $params
        ]);

but this still returns XML.

1

1 Answers

2
votes

Their documentation is bad.

I found hidden on a specific request that you need to add to the body params:

'format' => 'json'