Sharepoint and Microsoft Graph Bad Request

Hi,
I try to create a folder in Microsoft Sharepoint with Xamarin. But I only get Bad Requests.
It works, when I use the graph explorer from Microsoft Graph Explorer.

` public async void PushToAzure() {
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", App.AuthenticationResult.AccessToken);

        var body = "{\"name\": \"New Folder\",\"folder\": { }}";
        var contents = new StringContent(body);
        contents.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata=verbose");

        try {
            var postResult = await client.PostAsync("https://graph.microsoft.com/beta/sharepoint/site/drive/items/root/children/TravelXam/children", contents);
            var result = postResult.EnsureSuccessStatusCode();
            Debug.WriteLine(result);
            if (result.IsSuccessStatusCode) {
                Debug.WriteLine("List item created successfully");
            }
        } catch (Exception ex) {
            Debug.WriteLine("Unable to create list item " + ex.Message);
        }
    }`

I used this two Tutorials:
https://github.com/fabianwilliams/ignitebrk3114
https://blog.xamarin.com/add-collaboration-to-your-mobile-apps-with-sharepoint/
Somebody know how to fix this?

Sign In or Register to comment.