Skip to main content
New Participant
Oct 15, 2023 4:53 PM UTC

Unable to create a Box API connection using client ID and client secret

I am fairly new to Box Java API. I am trying to use the BoxAPIConnection API to get a connection to Box using client id and secret.

Here is the code that I am using as per the documentation:

BoxAPIConnection api = new BoxAPIConnection(“<client_id>”,“<client_secret>”);

I am getting the following error:

Exception in thread “main” com.box.sdk.BoxAPIResponseException: The API returned an error code [401 | .08eaad29f26b48b94acb1d577e5ceb51f]
at box.java.sdk@4.5.0/com.box.sdk.BoxAPIResponse.toBoxResponse(BoxAPIResponse.java:147)
at box.java.sdk@4.5.0/com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:616)
at box.java.sdk@4.5.0/com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:380)
at box.java.sdk@4.5.0/com.box.sdk.BoxJSONRequest.send(BoxJSONRequest.java:106)
at box.java.sdk@4.5.0/com.box.sdk.BoxJSONRequest.send(BoxJSONRequest.java:17)
at box.java.sdk@4.5.0/com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:347)
at box.java.sdk@4.5.0/com.box.sdk.BoxJSONRequest.send(BoxJSONRequest.java:101)
at box.java.sdk@4.5.0/com.box.sdk.BoxUser.getCurrentUser(BoxUser.java:199)

The code works fine if I call the API using developer token.

    6 replies

    smartoneinok Box
    Senior Developer Advocate
    Oct 16, 2023 3:43 PM UTC

    Hello 👋,

    May I have the client id of the application?

    Thanks,
    Alex, Box Developer Advocate 🥑

    Translate
    Oct 18, 2023 1:01 PM UTC

    Hi Team,

    I am also facing the same issue with Client ID & Client Secret. I am getting 400 error.
    box_subject_type" for the “client_credentials” grant type can not be used. This is my personal account I have created for Testing purpose only. I have to do this testing from personal as my corporate account does not allow Testing on enterprise ID.
    Here is my client ID: 9p0vtjne3m7ijzb3u2xwfcdotd0s9r7m
    can you pls assist?

    Translate
    smartoneinok Box
    Senior Developer Advocate
    Oct 18, 2023 6:48 PM UTC

    It looks like you are trying to use a Client Credentials authentication method - which is not possible with a free account. I changed your account a developer tarriff which should allow you to go through the process of approving the application.

    Translate
    Dec 1, 2023 10:45 AM UTC

    Hi Team,

    I am also facing the similar with Client ID & Client Secret. I am getting 400 error.
    box_subject_type" for the “client_credentials” grant type can not be used.
    This is my personal account I have created for Testing purpose only. I have to do this testing from personal as my enterprise account does not allow Testing on enterprise ID.
    Here is my client ID: r1gavbz254ttpcfjrg5kk5c92koleyzy
    can you pls help?

    Translate
    smartoneinok Box
    Senior Developer Advocate
    Jan 8, 2024 6:17 PM UTC

    @user144 You should have access to approve application in your admin console now. let me know if you get stuck.

    Translate
    New Member
    Dec 24, 2024 10:09 AM UTC

    Hi Team,

     

    I am also facing the similar with Client ID & Client Secret. I am getting 400 error.

    box_subject_type" for the “client_credentials” grant type can not be used.

    This is my personal account I have created for Testing purpose only. I have to do this testing from personal as my enterprise account does not allow Testing on enterprise ID.

    Here is my client ID: es0zd124z18wotpspprbzalnl2rcn1vu

    can you pls help?

    Translate