skip to Main Content

I’m currently researching Microsoft Graph API using .net and Microsoft.Graph Client Library 5.0.0 (https://www.nuget.org/packages/Microsoft.Graph/) and a GraphTutorial console app (https://developer.microsoft.com/en-us/graph#get-started).

When trying to grab my outlook calendar via the API, I’m getting Microsoft.Graph.Models.ODataErrors.ODataError exception. The problem is that it’s not telling me what exactly is wrong.

How can I get detailed information on the error? Such as, is it about permissions, query, or something different?

I tried diving into the Exception object, but I couldn’t find anything useful.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    OK, so it appears that Microsoft Graph API responses are not very verbose, but are rather using HTTP status codes to communicate errors. The full list of codes and their meaning cane be found here: https://learn.microsoft.com/en-us/graph/errors

    As for my question, you can see 403 response status code in the exception object (screenshot above) which is to be understood as:

    403 Forbidden: Access is denied to the requested resource. The user might not have enough permission or might not have a required license.

    According to Microsoft, on some occassions a more descriptive JSON object can be returned:

    The error response is a single JSON object that contains a single property named error. This object includes all the details of the error. You can use the information returned here instead of or in addition to the HTTP status code. The following is an example of a full JSON error body.

    {
      "error": {
        "code": "invalidRange",
        "message": "Uploaded fragment overlaps with existing data.",
        "innerError": {
          "request-id": "request-id",
          "date": "date-time"
        }
      }
    }
    

    However, I'm still not sure which property of an exception object I should look in for this JSON response.


  2. If you are using C# SDK you can add try-catch and catch ODataError

    try
    {
        await graphServiceClient...
    }
    catch (ODataError odataError)
    {
        Console.WriteLine(odataError.Error?.Code);
        Console.WriteLine(odataError.Error?.Message);
        throw;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search