Java SDK - 404 File Not Found on publicly available document
I;m using Box SDK to get an access token like this:
val MAX_CACHE_ENTRIES = 100
val accessTokenCache: IAccessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES)
val boxConfig: BoxConfig = {
// Read Box config file
val stream = getClass.getResourceAsStream( path )
val reader = new InputStreamReader( stream )
BoxConfig.readFrom( reader )
}
val connection: BoxDeveloperEditionAPIConnection = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache)
val accessToken = connection.getAccessToken()
Then with this access token and the file ID I send POST to read the file as follows:
val url = s"https://api.box.com/2.0/files/$fileId/content" target="_blank">https://api.box.com/2.0/files/$fileId/content>" target="_blank">https://api.box.com/2.0/files/$fileId/content" target="_blank">https://api.box.com/2.0/files/$fileId/content>>"
val header = List(Header("Authorization", s"Bearer $token"))
When I send the POST request with this auto generate token I get back a 404 File Not Found error, but if I manually generate a token from Box Developer Console the same code works and I can retrieve the file content.
Am I using the access token wrong?
What is the unit for expires_in? Is it possible to increase it?
-
:
A 404 indicates that the token you're using doesn't have access to the file you're trying to call. Keep in mind that the developer token you're using is associated with the user that's logged into the dev console when you generate it. However, if you're using a JWT app you're most likely defaulting to calling with the apps service account. You're only going to be able to successfully interact with content the user associated with your token either owns or has collaborator access to.
As for expires_at, this is the expiry time of the access token you're using. The default value is in seconds, and will always be 3600, or 1 hour.
I also wanted to make a quick note that you should never share your tokens with anyone, especially in public forums like this. I have redacted it from your original message!
Best,
Kourtney
Box Technical Support Engineer
Please sign in to leave a comment.
Comments
1 comment