2017-09-26 2 views
1

Je reçois l'erreur suivante:Bad Request Error 400 MS-Graph API OneNote

{ 
     StatusCode: 400, 
     ReasonPhrase: 'Bad Request', 
     Version: 1.1, 
     Content: System.Net.Http.StreamContent, 
     Headers: 
     { 
      client-request-id: 09bcf6bf-1c4a-4f9d-9713-42dfbed17ecd 
      request-id: 09bcf6bf-1c4a-4f9d-9713-42dfbed17ecd 
      Transfer-Encoding: chunked 
      x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"South Central US","Slice":"SliceB","ScaleUnit":"002","Host":"AGSFE_IN_3","ADSiteName":"SAN"}} 
      Duration: 395.8064 
      Cache-Control: private 
      Date: Tue, 26 Sep 2017 17:28:22 GMT 
      Content-Type: application/json 
     } 
    } 

Lorsque j'utilise ce code pour créer une nouvelle section dans un bloc-notes:

/// Create a new Section with the Patient Name as the displayName 
tempSectionName = LastNameEdit.Text.ToString() + " " + FirstNameEdit.Text.ToString(); 
string url = "https://graph.microsoft.com/v1.0/me/onenote/"; 

CreateSectionInNotebook(Globals.CurrentEMRNotebookID, tempSectionName, url); 

} 

/// <summary> 
/// Create a section with a given name under a given notebookId 
/// </summary> 
/// <param name="notebookId">parent notebook's Id</param> 
/// <param name="sectionName">name of the section to create</param> 
/// <param name = "apiRoute" ></ param > 
/// <remarks>Create section using a application/json content type</remarks> 

private async void CreateSectionInNotebook(string notebookId, string sectionName, string apiRoute) 
{ 
    var client = new HttpClient(); 

    // Note: API only supports JSON response. 
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 

    // Not adding the Authentication header would produce an unauthorized call and the API will return a 401 
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken); 

    // Prepare an HTTP POST request to the Sections endpoint 
    // The request body content type is application/json and require a name property 
    var createMessage = new HttpRequestMessage(HttpMethod.Post, apiRoute + @"notebooks/" + notebookId + "/sections") 
    { 
     Content = new StringContent("{ name : '" + WebUtility.UrlEncode(sectionName) + "' }", Encoding.UTF8, "application/json") 
    }; 

    HttpResponseMessage response = await client.SendAsync(createMessage); 
} 

Je essayé de faire correspondre les entrées du OneNote Service Samples Win Universal, mais il utilise l'API OneNote.

Ce serait bien si Microsoft Graph Explorer avait étendu MSGraph/OneNote capacités comme APIgee a pour API OneNote.

Répondre

0

L'explorateur MS Graph ne dispose échantillons OneNote - regarder pour eux sur le côté gauche.