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
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.