Skip to main content
Question

Cannot get a simple file download to work through box..api with curl

  • May 23, 2025
  • 4 replies
  • 82 views

Forum|alt.badge.img

I have run into 2 issues with my Custom App

Auth Method: OAuth 2.0 with Client Credentials Grant (Server Authentication)

App Access Level: App+Enterprise Access

Client id: ssunxw71at2t90vqe0m0goaj3ya6ol7h

 

1. Cannot get token associated with the user id

     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "client_id=ssunxw71at2t90vqe0m0goaj3ya6ol7h" \
     -d "client_secret=6*******************z" \
     -d "grant_type=client_credentials" \
    -d "box_subject_type=user" \
     -d "box_subject_id=19622242709"

Error message: {"error":"invalid_grant","error_description":"Grant credentials are invalid"}

Then I changed to authenticate through enterprise id, replacing the last two lines with

     -d "box_subject_type=enterprise"  \
     -d "box_subject_id=906015826"
 
I did get a token back that way. But why it failed through the user?
 
2. Cannot get any folder or item with token obtained through the enterprise id
 
FOLDER_ID='165911621075'
curl -i -X GET "https://api.box.com/2.0/folder/$FOLDER_ID/items" -H "Authorization: Bearer P*****************J"
 
{"type":"error","status":404,"code":"not_found","help_url":"http:\/\/developers.box.com\/docs\/#errors","messag
e":"Not Found","request_id":"f07bwyh5z1f62o2o"}
 
# try getting the file directly
curl -i -X GET "https://api.box.com/2.0/files/974807302538/content" -H "Authorization: Bearer $TOKEN" -L
 
{"type":"error","status":404,"code":"not_found","help_url":"http:\/\/developers.box.com\/docs\/#errors","messag
e":"Could not find the specified resource","request_id":"fwrqlyh5z21n3ztv"}
 
Please help!
 
Thanks,
Al
 
 

4 replies

Forum|alt.badge.img

Hi 

1. Most likely you need to ensure that your app has the 'generate user access tokens' advanced feature turned on (and re-authorize after you make the change)
BOX2_AwVsYuyob_O2KkH17NNwLg.png

2. Most likely the application service account does not have access to the folder you are trying to fetch. When you use the 'enterprise' subject in client credentials grant you will get a token for the service account. You can check this by running this API https://developer.box.com/reference/get-users-me/ which returns the current user. You can the copy the login from the output (should be 'AutomationUser....@boxdevedition.com') and share the folder using your logged in Box account. Then the API should return the folder.

Hope this helps
Rgds,
Peter Christensen, Platform Solutions Engineer, Box


Forum|alt.badge.img

Hi Peter,

Thanks for the prompt response. It works now after I checked the two boxes under "Advanced" as you suggested in solution 1: I was able to get the token as a user, then using the token to get folder and file. 

I think it'd be nice if the documentation gives some clear explanation on what those options would enable. Various bits of info seem to scatter in different urls, making it hard to understand what each of those options would entail. Thankfully we have a support forum with quick responses, which is much appreciated.


Forum|alt.badge.img

By the way, there is another issue: the email for re-authorization after changing config seems to have stopped working. I tried multiple times and waited and never receive the email to authorize the change. I had to create a new app. I actually had the old app working a couple of months ago but with the new app I forgot which bit of config change was critical. With a simple download not working, combined with the authorization email not arriving, I was suspecting something was broken on box.com. Thus the question.


Forum|alt.badge.img

Thanks for the feedback, I will be sure to pass that on and check on the email for app authorization

Rgds,
Peter