0

One of the API I am consuming requires a header to be a JSON string. I did send the headers in the JSON type but it doesn't seem to work. I am not sure what is the mistake I am making here.

$json = json_encode(
    [
    "parent_id" => "FgzDPEyJRhb-xZLC9yVhGOyaVQypI2TDSO6NQsnS",
    "name" => "dummy-1.txt",
    ]
);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization : ApiKey XXX',
    'X-Kloudless-Metadata :'.$json,    

));

The response I get is missing parent_id and name in the request.

Naveen Kumar
  • 1,476
  • 5
  • 28
  • 52
  • Look here: https://stackoverflow.com/a/27276406/11025032 – dobson Feb 28 '20 at 08:42
  • Are you sure the `X-Kloudless-Metadata` is a valid header for this values? – Beniamin Feb 28 '20 at 08:44
  • Also its value is for sure as kloudness expect? – Beniamin Feb 28 '20 at 08:45
  • Yes it is @Beniamin, This is the sample curl `"curl -X POST --header 'Content-Type: multipart/form-data' --header 'X-Kloudless-Metadata: {"parent_id":"FgzDPEyJRhb-xZLC9yVhGOyaVQypI2TDSO6NQsnS8nHbKNkCeicZmsiNKT5iqBfwv","name":"sample.txt"}' --header 'Authorization: APIKey XXX' -F file=@"sample.txt" 'https://api.kloudless.com/v1/accounts/365442359/storage/files/' "` – Naveen Kumar Feb 28 '20 at 09:17
  • 1
    https://incarnate.github.io/curl-to-php/ translates your cURL statement into `$headers[] = 'X-Kloudless-Metadata: {\"parent_id\":\"FgzDP…` regarding this header. I am not sure why the \ to escape the double quotes should be necessary here, but maybe try and see if that version works anyway? – CBroe Feb 28 '20 at 10:07

0 Answers0