F. Baum F. Baum - 1 month ago 19
C# Question

Confluence REST API Update a Page

This is my code to update a existing page. The Variables in the json aren't the problem, because I can create a page with this json without any problems.

string json = "{\"type\":\"page\",\"title\":\"" + "Tabelle " + table.Name + "\",\"space\":{\"key\":\"PROG\"},\"ancestors\":[{\"id\":120179837}],\"body\":{\"storage\":{\"value\":\"" + WARNING + table.BasisInfosHtmlString + table.TableStructurHtmlString + table.DependentTablesHtmlString + table.ReferencedInHtmlString + "\",\"representation\":\"storage\"}}}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = Client.PutAsync(@"/rest/api/content", content);


If I run this, I get server error 405. Don't know why, because I can easiely create a page with this using the POST Method.

I'm NOT hosting the API IIS myself.

Answer

You need to put the content id in the URL to update an existing page: PUT /rest/api/content/{contentId}.

var response = Client.PutAsync(@"/rest/api/content/{contentId}", content);

Ref.: https://docs.atlassian.com/confluence/REST/latest/#content-update