我使用GuzzleHttp向Pardots API发送请求。
class PardotIntegration {
private $client;
private $apikey;
public function __construct() {
$this->client = new \GuzzleHttp\Client();
}
public function authenticate() {
$params = [
'email' => 'abc@example.com',
'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();文档指出,您可以从请求中返回XML或JSON:http://developer.pardot.com/#changing-the-api-response-format
但是,我不知道如何返回JSON而不是默认的XML。
我试着添加了
$res = $this->client->post('https://pi.pardot.com/api/login/version/3', [
'headers' => [
'Accept' => 'application/json'
],
'form_params' => $params
]);但是这仍然返回XML。
发布于 2019-05-16 04:09:54
他们的文档很糟糕。
我发现隐藏在一个特定的请求中,您需要添加到body params中:
'format' => 'json'
https://stackoverflow.com/questions/56156765
复制相似问题