0

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.

double-beep
  • 5,031
  • 17
  • 33
  • 41
F. Baum
  • 301
  • 1
  • 5
  • 17
  • Possible duplicate of [ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8](http://stackoverflow.com/questions/10906411/asp-net-web-api-put-delete-verbs-not-allowed-iis-8) – Jek Oct 27 '16 at 13:24
  • It's not a duplicate, because I'm not hosting the IIS. It's confluence is hosted on the network in my company. – F. Baum Oct 27 '16 at 13:27

3 Answers3

2

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

mtheriault
  • 1,065
  • 9
  • 21
  • I tried this before, but without the brackets around the contentId. Should there be brackets? – F. Baum Oct 28 '16 at 04:54
  • No bracket, see the corresponding documentation. – mtheriault Oct 28 '16 at 11:55
  • 1
    If you update a page, you need to pass the incremented version in the JSON payload as stated in the documentation. And I see that you want to update the ancestor, not sure the space key is required in this case. – mtheriault Oct 31 '16 at 19:16
2

This is the code, which worked perfectly to update a page. Thanks to mtheriault for the answers!

string json = "{\"version\":{\"number\":2},\"type\":\"page\",\"title\":\"" + "Tabelle " + table.Name + "\",\"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/" + pageid, content);

Like stated, I had to increment the version number, also I had to put the pageid into the Uri.

F. Baum
  • 301
  • 1
  • 5
  • 17
1

If you are hosting the API iis might be blocking the Put verb for several reasons (actually WebDav might be root cause)

Check this link ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8

Community
  • 1
  • 1
Jek
  • 441
  • 7
  • 16