Box -> View API -> Can not create session for an document_id

ⅰ亾dé卋堺 提交于 2019-12-11 09:58:49

问题


To follow the instruction of Box.com View API on how to create a session

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

I use RestSharp to write code:

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;

But I got the response :

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

while document_id 19877746783 is exactly right.

I don't know why I got this message. Thank you


回答1:


The ID does not look like it was generated by the View API (they're 32 characters). The only IDs that will work with the View API are from documents that been uploaded directly to the View API using the POST /documents method first i.e. you'll make this API call

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

and will receive this response

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

You'll need to use DOCUMENT_ID to create the session in the method you have above.



来源:https://stackoverflow.com/questions/25283761/box-view-api-can-not-create-session-for-an-document-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!