Hi,
Am new to integrate the box view api and am using the php with curl for uploading the document to box(using the following code):
$URL = 'https://view-api.box.com/1/documents';
$apiKey = '<- redacted ->';
$filePath ='http://localhost/abc/upload/filename.pdf';
$file = json_encode(array('url'=>$filePath,'name'=>'Pdf File name'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Token ' . $apiKey,
'Content-Type: application/json',
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $file);
$response = curl_exec($ch);
curl_close($ch);
$decodedata = json_decode($response);
$documentid = $decodedata->id;
Output:
stdClass Object( [type] => document [id] => 0fc7975523b846b899efdb9383184e4f [status] => queued [name] => PDF File name [created_at] => 2015-10-15T06:10:17.486Z)
everytime am getting the queued status on uploading the documnet. and i used this document id to create session mean am getting error or empty responce.
//for session creation
$_sessionURL = 'https://view-api.box.com/1/sessions';
$apiKey = '<- redacted ->';
$documentid = json_encode(array('document_id'=>$documentid,'duration'=>60));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_sessionURL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Token ' . $apiKey,
'Content-type: application/json',
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $documentid);
$response = curl_exec($ch);
curl_close($ch);
output :
empty responce...
So please guide me to solve this problem.