meataxe meataxe - 1 month ago 6x
C# Question

How can I add a new document to Content Server 10.5 using the REST api

How can I add a new document to Content Server 10.5 using the REST api?

I am following the Swagger docs for creating a node, but it is not clear how I attach the file to the request. Here is (roughly) the code I am using:

var folderId = 2000;
var docName = "test";

var uri = $"http://[serverName]/otcs/llisapi.dll/api/v1/nodes?type=144&parent_id={folderId}&name={docName}";

var request = new HttpRequestMessage();
request.Headers.Add("Connection", new[] { "Keep-Alive" });
request.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
request.Headers.Add("Pragma", "no-cache");
request.Headers.Add("OTCSTicket", /* ticket here */);
request.RequestUri = new Uri(uri);
request.Method = HttpMethod.Post;
request.Content = new ByteArrayContent(data);
request.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeMapping.GetMimeMapping(filePath));
request.Headers.ExpectContinue = false;

var httpClientHandler = new HttpClientHandler
Proxy = WebRequest.GetSystemWebProxy(),
UseProxy = true,
AllowAutoRedirect = true

using (var client = new HttpClient(httpClientHandler))
var response = client.SendAsync(request).Result;
IEnumerable<string> temp;
var vals = response.Headers.TryGetValues("OTCSTicket", out temp) ? temp : new List<string>();
if (vals.Any())
this.ticket = vals.First();

return response.Content.ReadAsStringAsync().Result;

I've been searching through the
forums, but finding a complete example in c# is proving tough - there are a few examples in javascript, but attempting to replicate these in c# or via chrome or firefox extensions just give the same results. Calling other CS REST methods has not been an issue so far, this is the first one that's giving me problems.

Edit: I pasted the wrong url into my question, which I've now fixed. It was
var uri = $"http://[serverName]/otcs/llisapi.dll/api/v1/forms/nodes/create?type=0&parent_id={folderId}&name={docName}";


Your URL doesn't look like the REST API, it's rather the traditional URL used for the UI.

This article should describe how to do what you want to do:


Ok, so that's how it should work:

send a POST to[.exe]/api/v1/nodes

send this in your payload to create a document in your enterprise workspace


A incomplete demo in Python would look like this. Make sure you get a valid ticket first.

files = {'file': (open("file.txt", 'rb')}
data = { 'type': 144, 'parent_id': 2000, 'name': 'document_name.txt' }
cs =, headers={'otcsticket':'xxxxxxx'}, data=data, files=files)
if cs.status_code == 200:
    print "ok"
    print cs.text