Search code examples
c#httpclientconfluence-rest-api

Confluence REST API Update a Page


This is my code to update an 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.


Solution

  • 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