Microsoft graph api 使用路径返回 'invalidRequest' 创建文件夹
Microsoft graph api create folder using path returning 'invalidRequest'
图api返回以下错误:
"error": {
"code": "invalidRequest",
"message": "[child] A null value was found for the property named 'id', which has the expected type 'Edm.String[Nullable=False]'. The expected type 'Edm.String[Nullable=False]' does not allow null values.",
"innerError": {
"request-id": "36d65bbb-2f6e-485c-b2b9-5bb7fdb76d19",
"date": "2017-09-30T00:24:06"
}
}
我使用的代码:
var url = "https://graph.microsoft.com/v1.0/me/drive/root:/joba:/children";
var folder = new ItemResource { name = "nested", folder = new FolderFacet() };
var response = api.PostAsJsonAsync<ItemResource>(url, folder).Result;
response.ThrowWhenUnsuccessful();
return response.Content.ReadAsAsync<ItemResource>().Result;
也就是说,我正在尝试在 joba 文件夹(位于 root).
它不起作用...我什至试图转义冒号 :joba:
但它也不起作用。同样的请求在 graph-explorer
中工作得很好
我的怎么了?
编辑
提琴手请求
POST https://graph.microsoft.com/v1.0/me/drive/root:/wdg:/children HTTP/1.1
Accept: application/json
Authorization: Bearer <OMITED>
Content-Type: application/json; charset=utf-8
Host: graph.microsoft.com
Content-Length: 268
Expect: 100-continue
Connection: Keep-Alive
{"id":null,"createdBy":null,"createdDateTime":null,"eTag":null,"cTag":null,"description":null,"lastModifiedBy":null,"lastModifiedDateTime":null,"name":"85923635-56af-4902-82da-babd95165c6b","parentReference":null,"webUrl":null,"folder":{"ChildCount":null},"file":null}
PostAsJsonAsync
在幕后使用 Json.NET,默认情况下将序列化具有空值的属性。由于省略值与故意指定空值的处理方式不同,因此当发生这种情况时,它会触发 OneDrive API 认为请求无效,因为为不可空字段指定了空值。
要解决此问题,您可以将以下属性添加到 ItemResource
类型的可空属性中:
[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]
或者,您可以使用 Json.NET 直接序列化对象并提供适当配置的 JsonSerializerSettings
实例,然后调用 PostAsync
.
图api返回以下错误:
"error": {
"code": "invalidRequest",
"message": "[child] A null value was found for the property named 'id', which has the expected type 'Edm.String[Nullable=False]'. The expected type 'Edm.String[Nullable=False]' does not allow null values.",
"innerError": {
"request-id": "36d65bbb-2f6e-485c-b2b9-5bb7fdb76d19",
"date": "2017-09-30T00:24:06"
}
}
我使用的代码:
var url = "https://graph.microsoft.com/v1.0/me/drive/root:/joba:/children";
var folder = new ItemResource { name = "nested", folder = new FolderFacet() };
var response = api.PostAsJsonAsync<ItemResource>(url, folder).Result;
response.ThrowWhenUnsuccessful();
return response.Content.ReadAsAsync<ItemResource>().Result;
也就是说,我正在尝试在 joba 文件夹(位于 root).
它不起作用...我什至试图转义冒号 :joba:
但它也不起作用。同样的请求在 graph-explorer
我的怎么了?
编辑 提琴手请求
POST https://graph.microsoft.com/v1.0/me/drive/root:/wdg:/children HTTP/1.1
Accept: application/json
Authorization: Bearer <OMITED>
Content-Type: application/json; charset=utf-8
Host: graph.microsoft.com
Content-Length: 268
Expect: 100-continue
Connection: Keep-Alive
{"id":null,"createdBy":null,"createdDateTime":null,"eTag":null,"cTag":null,"description":null,"lastModifiedBy":null,"lastModifiedDateTime":null,"name":"85923635-56af-4902-82da-babd95165c6b","parentReference":null,"webUrl":null,"folder":{"ChildCount":null},"file":null}
PostAsJsonAsync
在幕后使用 Json.NET,默认情况下将序列化具有空值的属性。由于省略值与故意指定空值的处理方式不同,因此当发生这种情况时,它会触发 OneDrive API 认为请求无效,因为为不可空字段指定了空值。
要解决此问题,您可以将以下属性添加到 ItemResource
类型的可空属性中:
[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]
或者,您可以使用 Json.NET 直接序列化对象并提供适当配置的 JsonSerializerSettings
实例,然后调用 PostAsync
.