0
votes

We are doing a MS Graph API call to get the Sharepoint URL of a Team.

API URL: GET https://graph.microsoft.com/v1.0/groups/{GroupID}/sites/root/weburl

We get this :

Response:

{
  "error": {
    "code": "serviceNotAvailable",
    "message": "The service is not available. Try the request again after a delay. There may be a Retry-After header.",
    "innerError": {
      "request-id": "9f23d067-e851-4c43-8701-abe137683b87",
      "date": "2020-03-05T13:53:43"
    }
  }
}

What could be the issue?

3
Hi Vlad, as you can see the message states, the service is not available. Have you tried trying the request after a delay? Like really on a different day maybe even? Or just a few minutes later?jPO
Yes, I have , after some time, even after one day. The error message was the same so farvlad.orascu

3 Answers

1
votes

I have been experiencing a similar problem in searching sites ( GET /sites?search=* ) with the Graph API since March 2nd. I have not been able to recover. I have experienced this over multiple O365 tenants, both free and licensed.

Microsoft docs say this error code is due to MSFT induced throttling, but my request rate is like 50 per hour.

This seems to be a Microsoft bug. I posted a stack overflow issue for this and @rafa-ayadi reported that MSFT was fixing it their side for one of his customers.

I bought an Azure Developer Support subscription for this issue, but MSFT closed it and referred me to Sharepoint Developer Support, for which I can find no link or pricing. So no luck yet in getting MSFT to acknowledge and fix for me.

0
votes

/** You need do authentication delegated. See the follow code: First of all you need from portal.azure.com register app and get: folder id it is tenantID App Id. it is clientId **/

URL urlObj = new             
URL("https://login.microsoftonline.com/"+config.tenantID+"/oauth2/v2.0/token");
HttpURLConnection httpCon = (HttpURLConnection) urlObj.openConnection();

String urlParameters = "" + // para la v2.0
   "grant_type"+"="+"password"+"&"+ /
   "scope" + "=" + "https%3A%2F%2Fgraph.microsoft.com%2F.default" +"&" +
   "client_id" + "=" + config.clientId +"&" +
   "client_secret" + "=" + config.clientSecret +"&" +
   "username" + "=" + config.username +"&" +
   "password" + "=" + config.contrasena +"&";

byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
int postDataLength = postData.length;

httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpCon.setRequestProperty("Content-Length",String.valueOf(postDataLength));
httpCon.setRequestMethod("POST");

httpCon.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpCon.getOutputStream());
writer.write(urlParameters);
writer.flush();

int status = httpCon.getResponseCode();

BufferedReader in = new BufferedReader(new 
   InputStreamReader(httpCon.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
   content.append(inputLine);
}
in.close();
String body = getBody(content.toString());

String token = null;
final ObjectNode node = new ObjectMapper().readValue(body, ObjectNode.class);
if (node.has("access_token")) {
    token = node.get("access_token").asText();
}
httpCon.disconnect();

return token;
0
votes

My similar problem accessing any resource in the sites API was caused by having both the Groups.Create and Groups.ReadWrite.All permissions granted at the same time for application type access.

Removing Groups.Create allowed the all CRUD calls to be successful without serviceNotAvailable errors, even command line calls that just access sites.

Be sure to update admin grant and your token if you change the permissions for a test.

User @user13034886 mentioned the permission clash in another post.