I have UWP App and currently working with Microsoft Graph API. I am constantly running into issue.
The issue is when I tried to create ListItem at sharepoint, it throws an error.
StatusCode: 400, ReasonPhrase: 'Bad Request'
My code is as below
string accessToken = GlobalSettings.userToken;
string addItemJsonString = "{\"fields\":{\"Title\":\"This is test record\"}}";
string requestUrl = "https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items";
HttpClient client = new HttpClient();
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, requestUrl);
message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
message.Content = new StringContent(addItemJsonString, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
HttpResponseMessage response = await client.SendAsync(message);
I followed this link https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/listitem_create#request-body
Any help would be appreciable. :)
Thanks