Skip to main content
Question

I get a 404 error when I'm trying to download file via Box API every time.

  • May 22, 2025
  • 8 replies
  • 121 views

Forum|alt.badge.img

Premise · What I want to realize

I'm trying to download file in Box via Box API, but I get a 404 error every time.

Testing environment

What I did

Write a code

class BoxFileDownload extends ApiActor with ActorLogging {
	def receive: PartialFunction[Any, Unit] = {
		case _event: HttpRequestEvent => implicit val event: HttpRequestEvent = _event
			// Load the configuration file of the BOX application
			val reader = new FileReader(".../box/config.json")
			val boxConfig = BoxConfig.readFrom(reader)

			// Set a cache information
			val MAX_CACHE_ENTRIES = 100
			val accessTokenCache  = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES)

			// Generate an enterprise connection object of  Box Application
			val client = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache)

			// Download the Box file
			val boxFileId = event.endPoint.getQueryString("box_file_id").getOrElse(0)
			val file      = new BoxFile(client, boxFileId.toString)
			val info      = file.getInfo()
			val stream    = new FileOutputStream(info.getName)
			file.download(stream)
			stream.close()
	}
}

 

Problems occurring · Error messages

When you execute the above code, ...

com.box.sdk.BoxAPIResponseException: The API returned an error code [404 | 7g59i4fxq8w0vd3r] not_found - Not Found
        at com.box.sdk.BoxAPIResponse.(BoxAPIResponse.java:92)
        at com.box.sdk.BoxJSONResponse.(BoxJSONResponse.java:32)
        at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:579)
        at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:354)
        at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:329)
        at com.box.sdk.BoxFile.getInfo(BoxFile.java:452)
        at jp.co.dac.advr.planning_web.controllers.menu.BoxFileDownload$$anonfun$receive$2.applyOrElse(Index.scala:81)   = this line: val info = file.getInfo()

I got an errors. What shoud I do? Could you lend me a hand?

Thank you for reading.

8 replies

Forum|alt.badge.img

 you are currently making an API call as the enterprise (we call this a Service Account), not the user who owns the file. You will need to create a client for that user as is described here:

 

https://github.com/box/box-java-sdk#boxdevelopereditionapiconnectionasenterpriseuser


Forum|alt.badge.img

Thank you so much! I solved this problem with your teaching!!

...

...but, I got a new error :_(

 

At first, the corrected code is here:

class BoxFileDownload extends ApiActor with ActorLogging {
	def receive: PartialFunction[Any, Unit] = {
		case _event: HttpRequestEvent => implicit val event: HttpRequestEvent = _event
			// Load the configuration file of the BOX application
			val boxConfig = tryWith(getClass.getClassLoader.getResourceAsStream(SharedConf.planning.boxConf)) { boxConf =>
				BoxConfig.readFrom(new InputStreamReader(boxConf))
			}

			// Set a cache information
			val MAX_CACHE_ENTRIES = 100
			val accessTokenCache  = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES)

			// Generate an enterprise connection object of  Box Application
			val USER_ID = SharedConf.planning.boxUserId
			val api     = new BoxDeveloperEditionAPIConnection(USER_ID, DeveloperEditionEntityType.USER, boxConfig, accessTokenCache)

			// Download the Box file
			val boxFileId = event.endPoint.getQueryString("box_file_id").getOrElse(0)
			val file      = new BoxFile(api, boxFileId.toString)
			val info      = file.getInfo()
			val tmpFile   = File.createTempFile("box-", "-download")  // 一時ファイル
			val stream    = new FileOutputStream(tmpFile)
			file.download(stream)
			stream.close()

			log.debug(s"box download file = ${tmpFile.getPath()}")

			mkFileDownloadViewFromStream(info.getName, new FileInputStream(tmpFile))
	}
}

Next, the error is:

com.box.sdk.BoxAPIResponseException: The API returned an error code [403 | p6m06xfxtnkcbelx] access_denied_insufficient_permissions - Access denied - insufficient permission
	at com.box.sdk.BoxAPIResponse.(BoxAPIResponse.java:92)
	at com.box.sdk.BoxJSONResponse.(BoxJSONResponse.java:32)
	at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:579)
	at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:354)
	at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:329)
	at com.box.sdk.BoxFile.download(BoxFile.java:295)
	at com.box.sdk.BoxFile.download(BoxFile.java:283)
	at jp.co.dac.advr.planning_web.controllers.menu.BoxFileDownload$$anonfun$receive$2.applyOrElse(Index.scala:89) = this line: file.download(stream)

Could you lend me a hand again?


Forum|alt.badge.img

Forum|alt.badge.img

Thank you for replying again.

I think I already "As-User" enable my app.

 

BOX_hdp891gmxhrjluczblzg4zg44aoecya9.png

 

If it's possible, Could you show me the configuration screen of the setting required in this case?

https://dachd.ent.box.com/developers/console/app/APP_ID/configuration


Forum|alt.badge.img

If you made a change to the permissions needed, you will need to re-approve the app at the Admin console. See https://community.box.com/t5/How-to-Guides-for-Admins/Enabling-Custom-Built-Applications/ta-p/2188 for details


Forum|alt.badge.img

> If you made a change to the permissions needed, you will need to re-approve the app at the Admin console.

I already re-approved my app after change to the permissions needed at the Admin console.

 

Is there any other solution?


Forum|alt.badge.img

Hey ,

 

Could you make a ticket with us at support.box.com? Include a link to this forum thread and we'll be able to help you out.

 

Thanks!


Forum|alt.badge.img

We are running into same issue. we are using oAuth2.0 connection in our App (to connect to Salesforce via Salesforce Box APIs).

We configured the application scope as documented and also added the collaborators.  We get the access token, but when trying to access the folder (via backend API),

we get the error 'BoxApiRequest.BoxApiRequestException: The Box API responded with a 404 : Not Found'.  Can you help?