Zoopla Sandbox with cURL http header error

2019-05-23 03:04发布

I'm developing code for an estate agent to upload properties to Zoopla via their datafeed

I'm having problem adding a required profile to the http header that is required

The only example in the documentation is this test from linux:

echo '{ "branch_reference" : "test" }' |
curl --key /path/to/private.pem --cert /path/to/certificate.crt --data @-
--header "Content-type: application/json;
profile=http://realtime-listings.webservices.zpg.co.uk/docs/v1.1/schemas/listing/list.json"
https://realtime-listings-api.webservices.zpg.co.uk/sandbox/v1/listing/list

I'm having a problem adding the profile to the http header in cURL Here's my code:

$json['branch_reference']="test";
$json=json_encode($json);

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSLKEY,'private.pem');
curl_setopt($ch, CURLOPT_SSLCERT,'zpg_realtime_listings_1468337696150754_20160712-20260710.crt');
curl_setopt($ch, CURLOPT_URL, "https://realtime-listings-api.webservices.zpg.co.uk/sandbox/v1/listing/list");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'Content-Type: application/json', 
  'profile: http://realtime-listings.webservices.zpg.co.uk/docs/v1.1/schemas/listing/list.json'
  ));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
if(curl_error($ch)){echo "CURL ERROR ".curl_error($ch)."<br>";}
$result = curl_exec($ch);
curl_close($ch);

echo $result;

The response I'm getting from Zoopla is:

{ "error_advice" : "The Content-Type header is missing the 'profile' parameter. Please supply 'profile', specifying the schema URL for the method you are calling: /sandbox/v1/listing/list", "error_name" : "missing_profile" } 

Can anbody please advise on the correct way to add the profile to the header?

Thanx

1条回答
Bombasti
2楼-- · 2019-05-23 03:38

From their example, it looks like you should be passing the whole string as a single Content-Type HTTP header, rather than two separate ones:

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'Content-Type: application/json; profile=http://realtime-listings.webservices.zpg.co.uk/docs/v1.1/schemas/listing/list.json'
);
查看更多
登录 后发表回答