BOX API call count
AnsweredHello All,
We have a requirement to search for documents in BOX and create metadata on them. We are able to do this.
Question is with number of API calls. We are limited by certain number of API calls per month. So we need to know the count before executing.
Below is the code snippet removed all non box statements,
1. Initial config, how many API calls
//Initial config, 1 or 2 api calls?
BoxConfig boxConfig = BoxConfig.readFrom(reader);
BoxUser.Info userInfo = BoxUser.getCurrentUser(boxConn).getInfo();
//Initial config, 1 or 2 api calls?
2. Search
//search, most likely one api call for searchRange. how about iterating over the results?
BoxSearchParameters boxSearchParameters = new BoxSearchParameters();
boxSearchParameters.setScope(scope);
boxSearchParameters.setType("file");
boxSearchParameters.setContentTypes(contentTypes);
boxSearchParameters.setAncestorFolderIds(ancestorFolderIds);
boxSearchParameters.setQuery(boxQuery);
PartialCollection partialCollection = boxSearch.searchRange(x, y, boxSearchParameters);
Iterator pcIterator = partialCollection.iterator();
while(pcIterator.hasNext()){
returnString = pcIterator.next().getID();
}
//search, most likely one api call for searchRange. how about iterating over the results?
3. Update metadata
//Update metadata, most likely one api call on createMetadata?
mdtBox = new Metadata(jsonObject);
boxFile.createMetadata(mdTemplate, mdtBox);
//Update metadata, most likely one api call on createMetadata?
Thanks,
Sundar.
-
I help maintain the Box Java SDK that it appears you're using — I can give you guidance on the expected number of API calls for each usage pattern (assuming you're using the most current version of the SDK):
- The call to get info for the current user is 1 API call, but I'm a bit confused about what you're doing here — what is the BoxConfig being used for in this code sample? Should I assume that the BoxAPIConnection object is already instantiated and set up?
- The call to searchRange() is 1 call, iterating over the partial collection is free since it does not automatically fetch more results from the API. If you want more results than that call gave you, you'll need to make another call to searchRange().
- Adding metadata to a file is 1 API call.
You can check all of this for yourself by intercepting the API calls to Box and doing some logging/counting or whatever you want:
boxConn.setRequestInterceptor(new RequestInterceptor() { @Override public BoxAPIResponse onRequest(BoxAPIRequest request) { // Do whatever counting or logging you want with the request return null; } });
-
Hi Box Team,
As I mentioned in my email I removed all non box code including below:
Reader reader = new FileReader(configFile); (where config file is the json with keys).
setRequestInterceptor is what I need. Rest of your answers confirms our understanding is right.
The utility will search and update box file with metadata, we want to fine tune the solution to make as less api calls as possible.
Leaving aside getting connection etc which are one time, it is going to be:
1. 1 API call for updating metadata + total file count\limit (which seems to have a low ceiling of 200 per below document)
https://github.com/box/box-java-sdk/blob/master/src/main/java/com/box/sdk/BoxSearch.java
Is it possible to override this to 1000 (limit --> page size). We will try anyway and post the results back.
Is there a batch api where we could do this with lesser api calls.
Thanks for the quick response.
Sundar.
-
Per the Search API reference documentation, the maximum value for the limit parameter is indeed 200. The Java SDK does include a Batch API, but it does not work the way you're thinking — multiple search operations in a single batch would still each count against rate limits since our backend still has to do the work on those queries.
-
Yes, in general Batch API does not reduce the consumption of rate limits. This is because on the backend we still have to do the same amount of work to make N updates, whether it's in one API call or N API calls. That load on our backend systems is part of what our rate limits are designed to limit, not just network traffic to our data centers.
Please sign in to leave a comment.
Comments
5 comments