I have below code running fine from command line :
curl https://view-api.box.com/1/sessions \
-H "Authorization: Token API KEY" \
-H "Content-Type: application/json" \
-d '{"document_id": "626ef23c0c924328b6f61505786df619", "duration": 60}' \
-X POST \
-i
Here is what I have tried :
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://view-api.box.com/1/sessions',
CURLOPT_HTTPHEADER => array('Authorization :Token iiiiiiiiiiiiiiiiiiiijjjjj','Content-type : application/json'),
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(document_id => $docid,duration => 60)
));
$resp = curl_exec($curl);
curl_close($curl);
echo $resp;
Please suggest a PHP equivalent of the request . I am not sure how duration
and -i
will be handled here .
I am getting below error message in the above curl request .
Modified Request Code :
$curl1 = curl_init();
curl_setopt_array($curl1, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://view-api.box.com/1/sessions',
CURLOPT_HTTPHEADER => array('Authorization :Token API KEY','Content-type : application/json'),
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array("document_id" => $documentid)
));
$resp1 = curl_exec($curl1);
curl_close($curl1);
echo $resp1;
Error :
{"message": "Unsupported media type 'multipart/form-data; boundary=----------------------------6a38938da01d' in request.", "type": "error", "request_id": "5f212af123cb4f37be9926431714fc63"}
I have mentioned Content-Type : application/josn whereas it is taking multipart/form-data . Please help me !!