Skip to content

Get folder items and read the JSON response (entries list) #591

@ducphan30

Description

@ducphan30

Description of the Issue

I am trying to retrieve the files with the associated metadata template within a folder with a single request to the Box API (through the Box Java SDK).
I am using the “fields” param in the following API request :

GET https://api.box.com/2.0/folders/<folderId>/items?fields=metadata.enterprise.<metadata_template_name>,modified_at,name,size

I found out in the Box Java SDK the piece of code which is triggering the above request :

String fields = "metadata.enterprise.<metadata_template_name>,modified_at,name,size";
for (BoxItem.Info itemInfo : boxFolder.getChildren(fields)) {
	// Do something
}

But… I did not find in the SDK a straightforward way to read the JSON response.
We just need to read the "entries" list in the JSON response (files information + metadata) without having to send additional requests to the Box API for performance optimization purposes.

What we don't want to do

for (BoxItem.Info itemInfo : boxFolder.getChildren(fields)) {
	if (itemInfo instanceof BoxFile.Info) {
		BoxFile file = ((BoxFile.Info) itemInfo).getResource();
		BoxFile.Info fileInfo = file.getInfo(); // <--- This line causes a new request to the Box API and we want to avoid that.
	}
}

Versions Used

Java Box SDK: 2.9.0
Java: 1.8

Questions

Am I supposed to use the BoxAPIRequest and BoxAPIResponse classes directly ?
Is there another way to avoid doing it manually ?
Please note that it is impacting one of our projects in a professional environment.
Thanks for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAdded to questions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions