盒子 - >查看API - >无法为document_id创建会话

时间:2014-08-13 10:25:25

标签: .net restsharp box-view-api

按照Box.com View API的说明,了解如何创建会话

curl https://view-api.box.com/1/sessions \
-H "Authorization: Token YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"document_id": "ABC123"}' \
-X POST

我使用RestSharp编写代码:

var client = new RestClient("https://view-api.box.com/1/sessions");
            RestRequest request = new RestRequest(Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Authorization", "Token r6bcsuizpt18hwf9fsq7l15oj7fts12x");
            request.AddHeader("Content-type", "application/json");

            request.AddBody(new { document_id = "19877746783" });
            var response = client.Execute<HttpResponseMessage>(request).Content;

但我收到了回复:

{"message": "Bad request", "type": "error", "details": [{"field": "document_id", "message": "Ensure this value has at least 32 characters (it has 11)."}], "request_id": "1e5ea09a373546c283d676d5c890cecb"}

虽然document_id 19877746783完全正确。

我不知道为什么收到这条消息。 谢谢

1 个答案:

答案 0 :(得分:0)

该ID看起来不像是由View API生成的(它们是32个字符)。使用View API的唯一ID来自首先使用POST /documents方法直接上传到View API的文档,即您将进行此API调用

curl https://view-api.box.com/1/documents \
-H "Authorization: Token YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "URL_TO_DOCUMENT"}' \
-X POST

并将收到此回复

{
    "type": "document",
    "id": "DOCUMENT_ID",
    "status": "done",
    "name": "",
    "created_at": "2013-08-30T00:17:37Z"
}

您需要使用DOCUMENT_ID以上述方法创建会话。