Groups from Box API
I have a user, which is a co-admin to manage Users and Groups.
Via Box UI, I can add groups as collaborator for a folder, I have access to all groups.
Via Box API, when I list the groups of the enterprise, with this same user, I receive an empty list as a response.
As you can see, for a specific group, I should be able to see it:
Every time, I receive this response from the API:
https://api.box.com/2.0/groups 200 {"total_count":0,"entries":[],"limit":100,"offset":0}
Is there any other access rights that I should set?
From the administration UI I have lots of groups (5 pages), so why is the result empty?
My code:
String strToken = ""; String URL = "https://api.box.com/2.0/groups" ; System.out.println(URL); HttpURLConnection connection = null; try { connection = (HttpURLConnection) new URL(URL).openConnection(); connection.setRequestMethod("GET"); connection.addRequestProperty("Authorization", "Bearer " + strToken); connection.addRequestProperty("Accept-Charset", "utf-8"); connection.addRequestProperty("Content-Type", "application/json"); connection.connect(); int status = connection.getResponseCode(); System.out.println(status); int BUFFER_SIZE = 8192; InputStreamReader input = new InputStreamReader(connection.getInputStream()); StringBuilder builder = new StringBuilder(); char[] buffer = new char[BUFFER_SIZE]; try { int read = input.read(buffer, 0, BUFFER_SIZE); while (read != -1) { builder.append(buffer, 0, read); read = input.read(buffer, 0, BUFFER_SIZE); } input.close(); } catch (IOException e) { System.out.println(e.getStackTrace()); } String jsonText = builder.toString(); System.out.println(jsonText); connection.disconnect(); } catch (IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); }
-
Hello Claire,
In order to call the endpoint to get all groups for enterprise, you will need to make that call with an enterprise admin scoped access token. Making the call as you did below with a user-scoped token will result in the empty response you received below.
It's a good idea to retain the enterprise admin token in your application to perform operations such as getting all of the enterprise groups, creating or updating users, etc.Try it again with the entrerprise scope and that should return the expected response.
Hope that helps! Let us know if you continue to have issues.
サインインしてコメントを残してください。
コメント
1件のコメント