Skip to main content
Question

Unable to access Box File System with Developer Token using Box JDK

  • May 22, 2025
  • 2 replies
  • 72 views

Forum|alt.badge.img

I have obtained a 60 minute developer token but cannot then use it in the advertised code snippet. In the below, everything is fine until I run the for(...) line in my debugger when I get the error message:

Exception in thread "main" com.box.sdk.BoxAPIResponseException: The API returned an error code [401 | 42vo6ygjyyshi0ay.05ffad8337146eb879749677ff77429db] unauthorized - Unauthorized - Cannot authorize with this service

I am using box-java-sdk-2.50.1.jar along with minimal-json-0.9.1.jar. Employees of my company use our enterprise Single Sign On (SSO) to access Box.

*****

public static void main(String[] args) {

  BoxAPIConnection api = new BoxAPIConnection("pasted-in-token");

  BoxFolder rootFolder = BoxFolder.getRootFolder(api);

  for (BoxItem.Info itemInfo : rootFolder) {

      System.out.format("[%s] %s\n", itemInfo.getID(), itemInfo.getName());

  }

}

 

 

2 replies

Forum|alt.badge.img

Hello Jonathan, 

Can you confirm the authentication method you're using and that your application has been correctly authorized in the Box admin console? 

Best, 

Kourtney


Forum|alt.badge.img

Hi Kourtney,

I am using Standard OAuth 2.0 (User Authentication). Here is a screen shot from the Box admin console:

BOX__ZLe2ju82RtF2cvxLyAGCHQ.png

Although this method says that it "Requires Box users to log in with a username and password to authorize your app to access content in their account" this never seems to happen, though I am logged into Box in an independent browser window. I would actually prefer not to use this method but I could not find a code snippet that showed how to use with OAuth 2.0 Credentials.

 

Jon