Skip to main content

When I use the Docebo API explorer to test the creation of a branch using:

{"code":"TEST001",
"id_parent":1}

the response I get (which I expect) is “Bad Request” and message “Branch code already exists”

But when I call the endpoint from my application with this code (modified to not expose our endpoint):

            values = new Dictionary<string, string>();
            values.Add("code", "TEST001");
            values.Add("id_parent", "1");

            content = new FormUrlEncodedContent(values);

            response = await client.PostAsync("https://endpoint/manage/v1/orgchart", content);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                Console.WriteLine("ERROR: returned " + response.ReasonPhrase + "\n");
            }

 

I get StatusCode: “Bad Requst” and ReasonPhrase “Bad Request”.

 

I have made lots of calls (including POST) to other Docebo API endpoints, but I have not been able to get anything sensible out of my POSTs to manage/v1/orgchart. What am I doing wrong?

 

Thanks for your help!

Hi ​@JimM,

I don't see a header with authentication, but I assume that since your other requests are working you have this sorted. 

You will need to specify a branch name. This is specified as a translation. So, the following json body will create a branch off the root (branch id 0) with a name in English of "Branch name".

{

  "code": "CD002",

  "id_parent": 0,

  "translations": {

    "en": "Branch name"

  }

}

Give that you are using x-www-form-urlencoded you might try one of the following.:

Add the following to your values (with a nod to Mr Google here, I am not a C# expert)

 

 values.Add("translationsren]", "Branch name");

 

Or use a json body

 

var jsonPayload = new StringContent(JsonConvert.SerializeObject(new

{

    code = "TEST001",

    id_parent = 1,

    translations = new

    {

        en = "string"

    }

}), Encoding.UTF8, "application/json");

 

response = await client.PostAsync("https://endpoint/manage/v1/orgchart", jsonPayload);

 

Does that make sense?

Peter


 

Hi ​@pdevaney 

Thanks for your guidance – I’m sorted now. I’m able to create a branch with a call to the API.

My mistake was to not be looking at

responseString = await response.Content.ReadAsStringAsync();

which is where I can see the error “Branch code already exists”. It makes sense now, I was not looking at the full result of the call to the API and I was misinterpreting part of it which lead me to believe I was doing something wrong.

Thanks so much for your help, I really appreciate your time and attention, particularly at this time of year.

 


Reply