Home AppWorks

Create node from C#

Hello. Hope someone can point me in the right direction here.
Using Content Server 16.2 API, trying to create a node using the following code:

        using (var htc = new HttpClient())
        {
            htc.DefaultRequestHeaders.Add("OTCSTICKET", GetOTAuthHeader());
            MultipartFormDataContent MFDC = new MultipartFormDataContent();
            MFDC.Add(new StringContent("144"), "type");
            MFDC.Add(new StringContent("102417"), "parent_id");
            MFDC.Add(new StringContent("testfromcsharp"), "name");
            byte[] bb = ct.Files[0].File;
            ByteArrayContent file = new ByteArrayContent(bb);
            MFDC.Add(file);
            var response = htc.PostAsync(ConfigurationManager.AppSettings["OTBaseUrl"] + "/api/v2/nodes", MFDC).Result;
        }

I'm getting a pretty vague 500 response:

{StatusCode: 500, ReasonPhrase: 'Internal server error', Version: 1.1,
Content: System.Net.Http.StreamContent, Headers: { Date: Tue, 09 Oct
2018 21:28:13 GMT Server: Microsoft-IIS/10.0 X-Powered-By: ASP.NET
Content-Length: 230 Content-Type: text/html }}

Is my call correct? Anything missing?

Comments

  • Hi Peter, I have the same issue and the same error, in addition on the thread.log I get this:
    "INFO Dispatcher error: Could not process object, invalid action 'create'"

    Is there anyone that can provide us a working C# example ?

Sign In or Register to comment.