Skip to main content
Question

Error: Grant credentials are invalid 2022

  • May 22, 2025
  • 4 replies
  • 14 views

Forum|alt.badge.img

Hi, I am getting an error when I try to use box_subject_type and box_subject_id as the user and user id when trying to generate an access token. 

{
    "error": "invalid_grant",
    "error_description": "Grant credentials are invalid"
}
 
I am using OAuth 2.0 Client Credentials Grant (Server Authentication) with App+Enterprise Access.
 
ClientId: ffc823n3uuf15g5vooj45xg3eri29ukn
 
 

4 replies

Forum|alt.badge.img

Hello, 

Couple of follow up questions for you. 

May I see the code you are running? 

Have you tried it with the enterprise keyword and enterprise id? 

Alex, Box Developer Advocate


Forum|alt.badge.img

Hello Alex,

I am trying to upload files via API, and enterprise id doesn't work for that.

Although, I am able to successfully generate an access token with enterprise id, I get this error when running my upload code:

{"type":"error","status":404,"code":"not_found","context_info":{"errors":[{"reason":"invalid_parameter","name":"parent","message":"Invalid value 'd_155054681560'. 'parent' with value 'd_155054681560' not found"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Not Found","request_id":"hbgddxh0allyle98"}

This is the code I am using.

BOX1_iCzhZmsZQ7LoyZ1xwIBizA.png

 

That is why I am trying to use user and user id in box_subject_id and box_subject_type, but I am getting this error.

BOX1_zvBGLg4MAQi1Ni22nCDwPQ.png

 

 

 


Forum|alt.badge.img
Hello  1917655670565

I see that in your example you created a connection with directly passed access token instead of using one of these constructor:

BoxCCGAPIConnection api = BoxCCGAPIConnection.applicationServiceAccountConnection(
"client_id",
"client_secret",
"enterprise_id"
);
BoxCCGAPIConnection api = BoxCCGAPIConnection.userConnection(
"client_id",
"client_secret",
"user_id"
);

Please visit this documentation page for more details about how to use CCG https://github.com/box/box-java-sdk/blob/main/doc/authentication.md#client-credentials-grant


User connection
 
The reason why user BoxCCGAPIConnection.userConnection() is not working for you is probably due to missing your app's authorization by an admin.
Please go to your app in https://app.box.com/developers/console/. Then go to "Authorization" tab at the top and click "Review and Submit". After that your admin should accept this changes.


Account Service connection

The reason why you cannot upload a file using enterprise connection is that account service is separate from the Box accounts of the application developer and the enterprise admin of any enterprise that has authorized the app — files stored in that account are not accessible in any other account by default, and vice versa. https://developer.box.com/guides/getting-started/user-types/service-account/.

So after you created an BoxCCGAPIConnection.applicationServiceAccountConnection() connection
you should use `asUser()` function described here https://github.com/box/box-java-sdk/blob/main/doc/authentication.md#as-user to make API calls on behalf of managed user which has access to this folder `155054681560`. But in order to do this you should firstly turn on "Make API calls using the as-user header" on your https://app.box.com/developers/console app on "Configuration" tab and "Advanced Features" section. Then you should go to "Authorization" tab at the top and click "Review and Submit". After that your admin should accept this changes.

Please let me know if it helped you.

Regards,
Artur






Forum|alt.badge.img

Thank you Artur Jankowski,

The issue has been resolved.