错误的请求错误400 MS-OneNote的图形API

问题描述:

,我发现了以下错误:错误的请求错误400 MS-OneNote的图形API

{ 
     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 
     } 
    } 

当我使用此代码来创建一个笔记本新的一节:

/// 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); 
} 

我有试图匹配来自OneNote Service Samples Win Universal的输入,但它使用OneNote API。

如果Microsoft Graph Explorer扩展了MSGraph/OneNote功能(如APIgee)对于OneNote API的功能,那将会很不错。

Microsoft Graph的有效负载与OneNote API略有不同。

在这种情况下,你需要设置的,而不是“名”

以备将来参考“显示名”,这里的微软图形文档:https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/notebook_post_sections

的MS图形探险家确实有OneNote的样本 - 看为他们在左边。