Content API Question: File ID is available but Cannot Download it. Return 404 Error
回答済みHello,
I got a error when using Content API and I would be very appreciate if anyone can provide any clue.
1. I can retrive file_id (assume removed for privacy96) using shared_link:
curl https://api.box.com/2.0/shared_items \
-H "Authorization: Bearer My_App_User_Access_Token" \
-H "BoxApi: My_File_Shared_Link"
2. Then I tried to use following command to get file information:
curl https://api.box.com/2.0/files/My_File_Id \
-H "Authorization: Bearer My_App_User_Access_Token"
3. I got following error response (removed for privacy96 is the file_id):
{"type":"error","status":404,"code":"not_found","context_info":{"errors":[{"reason":"invalid_parameter","name":"item","message":"Invalid value 'f_93315574096'. 'item' with value 'f_93315574096' not found"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Not Found","request_id":"removed for privacy57c6dd38cce04"}
Could anyone tell me what I did wrong? I generated App User JWT, then use it to get Access Token and used it in statements above. I can upload file and create folder, but then I cannot download them. I always get 404 error.
-
Hi I have this problem solved. The reason of this problem is in my old way, I messed up with Enterpise Token and App User Token. I created a temporary user every time I tried to get authentication using enterprise token. These users (after I check my user list, a lot...) did not have access to my file, which resulting in 404 error.
My correct way of getting through authetication:
1. Generate JWT using my Enterprise ID
2. Use this JWT to send a post request to Box API 'https://api.box.com/oauth2/token' to get Enterprise Access Token
3. Use https://api.box.com/2.0/users -H "Authorization: Bearer EnterprisAccessToken" to get user_id
4.Generate JWT using my user_id
5. Use new JWT to get User Access Token
6. Use User Access Token to download my file
For any one who may have same problem as me, https://docs.box.com/docs/app-users provide a good explaination about the difference between enterprise token and user access token.
And thank you for your help!
-
I'm not sure what programming language you use, but I remember I used a JavaScript JWT token library. This link has all libraries you can use https://jwt.io/#libraries-io.
-
I am using python as below to generate the enterprise token, but I don't know how to generate the user access token using user id
auth = JWTAuth(client_id=CLIENT_ID,client_secret=CLIENT_SECRET,enterprise_id=ENTERPRISE_ID,jwt_key_id=JWT_KEY_ID,rsa_private_key_file_sys_path=PRIVATE_KEY_FILE,)print("enterprise access token: ", auth.authenticate_instance())
サインインしてコメントを残してください。
コメント
8件のコメント