Unable to get file download URL
回答済みI am trying to get a download link of a file, but getting this error: invalid value 4.
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"file_version_id","message":"Invalid value '4'."}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"48y8omgyw5auncay"}
here is my code sniped:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.box.com/2.0/files/" . $fileId . "/content?version=4");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer " . $accessToken
));
// Receive server response ...
$server_output = curl_exec($ch);
$downloadDetails = json_decode($server_output);
curl_close($ch);
Not getting any idea why i am getting this. Can anyone help me out?
-
Hi Alauddin
For the version parameter you need a valid version ID.
Use the https://developer.box.com/reference/get-files-id-versions endpoint to list older versions of your file and use the version ID of the one you want to download.
curl_setopt($ch, CURLOPT_URL, "https://api.box.com/2.0/files/" . $fileId . "/content?version=ADD_THE_CORRECT_VERSION_ID_HERE");
Best regards, Peter Christensen, Platform Solutions Engineer, Box
-
hi
Not sure what you mean? The endpoint you are using https://developer.box.com/reference/get-files-id-content/ returns a binary result, not a json
If you are looking for file info rather than the actual content you can use this endpoint https://developer.box.com/reference/get-files-id/ or this one for versions https://developer.box.com/reference/get-files-id-versions-id/
Best regards,
Peter
-
Sorry, I was talking about Get Download URL. It is returning data like below. Not returning json.
HTTP/2 302 date: Fri, 04 Feb 2022 01:19:46 GMT location: https://public.boxcloud.com/d/1/b1!mCOaH-visH4TWpj2tgwhK6Gj_pFX8KIkmVNQdTgLyRAwuDYXXxRSwpVPVG5viDlFT7ch1gDvohs7BnHKSHFZsuDj1LVzD4-icW_OLPhVck1vovqVaoDsIuUwOG7azyeeK-vPrmYYgVt8TFdEYNA409bc75xEx34rD_9_tjg9Q8btN3r_4Pgv9u0lX2IDfwFzXi9DBdlyAyfhWVS2_pHG4EEmlKQNq5rK5ZFe8Ps-A_G7P6jdRSxoTpvCQwmNUXhWX_Y4XwUQNxDy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cRmDeYEw-Yvgv2pcKdPa46gfYzxUdYiZJE-GvwGHh7mpI0K0dhjFEQ../download x-envoy-upstream-service-time: 458 box-request-id: 01b89a29423847e7f518b7384208ff2d6 cache-control: no-cache, no-store strict-transport-security: max-age=31536000
-
The https://developer.box.com/reference/get-files-id-content endpoint will (almost) always return a 302 with location header instruction the client where to download the file.
This endpoint will not return any json payload. Are you asking because the file you are trying to download is a json file? To read it you will need to download it first
投稿コメントは受け付けていません。
コメント
6件のコメント