404 Not found error while uploading file to box from JWT REST API
Hi,
I am using Box api with JWT, I am successfully able to connect and authenticate with the access token and can read the file, however when i am trying to upload file it keep on throwing the 404 not found error.
I am using Guzzlehttp library and Firebase, the documentation in box is limited so I am not sure what exactly wrong with the code.
Here is the code that I am using:
$response = $client->request('POST', 'https://api.box.com/2.0/files/content', [ 'headers' => [ 'Authorization' => "Bearer {$access_token}", 'As-User'=>"77390W773", 'Accept' => "multipart/form-data", ], 'multipart' => [ [ 'name' => "attributes", 'contents'=>json_encode(['name'=>"test.txt",'parent'=>['id'=>"71425210032"]]) ], [ 'name' => "file", 'contents' => fopen("/home/vser/public_html/ss/box/test.txt", 'r'), ], ] ])->getBody()->getContents();
I just trying to make a test upload on the folder, I went through the document which is mentioned here:
https://developer.box.com/reference#upload-a-file
Let me know if anything wrong that i am doing here.
Thanks
-
You're most likely using the default token for your JWT app, which is for the application's service account. You either need to add this service account as a collaborator on the content you're trying to access or get a token for someone who currently does have access. This can be done in the sub-claim of your JWT assertion.
-
How do you add the service account as collaborator? When I go to a folder and try to share and pick the service account, but dont see any. I am developing a process to upload files to folders and it is giving me not founds. This seems like the issue, but have no idea how to give service account rights to the folder.
-
I have been struggling with this issue and finally figured out a solution - posting it here for any poor souls like me who finds the many threads like this one with no answers. The solution is to share the folder to your service account ID from the web page, just as if you were sharing to a new person by entering their email. You will find your service account ID under General Settings in the Box Developer Console. Once you've added the service account, the name of your app will show up as a user in the sharing panel. Make sure the access is set to Editor.
Please sign in to leave a comment.
Comments
3 comments