错误请求错误400 MS-Graph OneNote API

时间:2017-09-26 17:41:43

标签: microsoft-graph 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有用,那就太好了。

2 个答案:

答案 0 :(得分:0)

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

在这种情况下,您需要设置&#34; displayName&#34;而不是&#34; name&#34;

对于将来的参考,请参阅Microsoft Graph文档:https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/notebook_post_sections

答案 1 :(得分:0)

MS Graph资源管理器确实有OneNote样本 - 在左侧查找它们。