8

I am making requests to the Microsoft Graph REST api (beta), specifically to the sign-in event endpoint: https://graph.microsoft.com/beta/auditLogs/signIns

I am making batch requests that retrieve sign-ins for a particular user in batches of 1000. Starting around the 25th of september, these requests would fail after roughly 10-50 batches, with the following response, with a 400 (Invalid Request) HTTP error code:

"error": {
  "code": "",
  "message": "Token not found: token is either invalid or expired",
  "innerError": {
    "request-id": "[request-id-redacted]",
    "date": "2019-09-30T22:27:36"
  }
}

However, if I retry the requests after waiting ~1s, with the very same JWT web token, the requests succeed and I'm able to complete all the batch requests for the job I'm running. The access token I receive when initially authenticating expires in 1 hour, but this error crops up ~1-15 minutes after I receive the token (I've confirmed the unix timestamp expiry date I get w/ the token).

I'm wondering what could be the cause of this error, and how I could avoid it, other than hard-coding the specific response message and retrying. I was unable to find any matches on google for the error message, either. Has anyone seen this error before from the Microsoft Graph API?

GoogieK
  • 371
  • 2
  • 14
  • where you able to resolve this issue? from your understanding, the error message refers to the *access token* or to the *skip token* received from the API to retrieve the next batch? we are also seeing the same issue when working with 1000 batches and when working with the signIns api-version=beta. thanks – Roman Blachman Feb 15 '20 at 00:08
  • Looks like on our end we ended up hard-coding a retry when we encounter this error. However, looking at recent logs I don't see any occurrences of this error being caught by our systems, so we haven't run into it in a while. – GoogieK Feb 19 '20 at 17:23

2 Answers2

3

"I was unable to find any matches on google for the error message, either. Has anyone seen this error before from the Microsoft Graph API?"

Yes. I'm querying the https://graph.microsoft.com/beta/reports/credentialUserRegistrationDetails MS Graph endpoint, and I'm seeing exactly the same thing you are. Intermittent responses with status code 400 and this error message: "Token not found: token is either invalid or expired", only a minute after requesting an access token.

I'm using the @odata.nextLink value to page through the results, however it's proven to be very unreliable due to this issue. Sometimes I will get the entire set of results, other times I will only get a portion of it. Even when I sleep for 5 seconds between each nextLink request, the error still appears.

This started happening for me this week. Before I was getting consistent results.

Your approach to perform a retry might be the best one for now:

if response.status_code == 400:
  retry_request()
0

This seems to be a bug. According to this bug ticket it appears some scenarios may incur a higher count against the documented 20 limit. You may want to try throttling yourself, so that the requests are sent out at a slower rate.

Software2
  • 2,358
  • 1
  • 18
  • 28