1
votes

The error response I get from Graph API is below.

{ "error": { "code": "ErrorItemNotFound", "message": "The specified object was not found in the store.", "innerError": { "request-id": "c2b32b83-5ccf-4385-bee1-33afcc31deb0", "date": "2016-07-25T00:25:16" } } }

When I try to deserialize the response into my own error object i get an error

Unexpected character encountered while parsing value: . Path '', line 0, position 0.

Copy the above JSON and try validate using this tool https://jsonformatter.curiousconcept.com/

Anyone else having the same issue?


UPDATE

Sorry for late response guys. Below is the exact code i am using. I've just tested this again and i am getting the same error.

Enpoint URL: https://graph.microsoft.com/v1.0/users/MY_USER@EMAIL/events/

// New rest client with the destination URL.
        var client = new RestClient(url);

        // Type of request
        var request = new RestRequest(requestType);

        // Headers
        request.AddHeader("Authorization", "Bearer " + accessToken);
        request.AddHeader("Content-Type", "application/json");


        // Content serialized in a json format  
        if (requestType == Method.POST || requestType == Method.PATCH || requestType == Method.PUT)
        {
            var jsonBody = JsonConvert.SerializeObject(requestContent);
            request.AddParameter("application/json", jsonBody, ParameterType.RequestBody);
        }


        var response = await client.ExecuteTaskAsync(request);

Body of the request

{"Id":null,"Subject":"Maths","UserEmailAddress":"[email protected]","Start":{"DateTime":"2016-09-1T10:11:56","TimeZone":"Pacific/Auckland"},"End":{"DateTime":"2016-09-1T11:11:56","TimeZone":"Pacific/Auckland"},"Location":null,"Body":null,"ReminderMinutesBeforeStart":60,"IsReminderOn":true}
1
Hi Thivy, Thanks for trying out Microsoft Graph. Would you mind sharing more information about this issue? Which endpoint are you trying to access? Can you share the request with us? - Sky Liu - Microsoft
As you have already done, the mentioned error payload seems to valid JSON. Are your using the client SDK (if so, what platform?) ? If not, what library are you using to deserialize the JSON payload? - Sriram Dhanasekaran-MSFT
Could you provide a sample of your deserialization code? The JSON itself is valid. - Marc LaFleur

1 Answers

3
votes

The JSON text you posted actually contains the 3-byte UTF-8 BOM (0xEF 0xBB 0xBF). That will cause most JSON parsers to fail.

A simple workaround to your issue would be to detect the BOM and strip it before you parse.

Assuming JavaScript, something like below will solve your immediate issue.

<!-- language: lang-js -->
// Reading the string into JavaScript will convert the BOM from the 3-byte
// version to the 2-byte version (0xFEFF).
json = json.replace(/^\uFEFF/, '');

-

More

It would be much more valuable to figure out why this is even getting appended to the resulting error in the first place. How are you making the request that results in this error? If this is from a webpage, what is the page encoding? Are you setting any other HTTP request headers that may pertain to the desired encoding?