jiraconfluencejira-rest-apiconfluence-rest-api

Update a page in Confluence using REST API


This is what I've currently got and it creates a new Confluence page. It doesn't update it. Also it posts it in the root space, TST, but I want it to be in TST/space1/subsection2/updateThisPage.

curl -v -u admin:admin -X POST -H Content-Type: application/json -d  "{\"id\":\"123456\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"TST\",\"title\":\"updateThisPage\"},\"body\":{\"storage\":{\"value\":\"<p>This is the updated text for the new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":3}}" http://localhost:8090/rest/api/content?spaceKey=TST&title=updateThisPage

This is the error message I get

{"statusCode":400,"message":"A page with this title already exists: A page already exists with the title new page in the space with key TST"}

Would it be a permissions error? I know I do not have access to delete.


Solution

  • Use request path PUT /rest/api/content/{id}.

    This worked for me.

    curl -u admin:admin -X PUT -H "Content-Type: application/json" -d "{\"id\":\"26738701\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"RO\"},\"body\":{\"storage\":{\"value\":\"<p>UPDATE This is a new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":2}}" http://localost:10080/rest/api/content/26738701
    

    JSON Payload:

    {  
       "id":"26738701",
       "type":"page",
       "title":"new page",
       "space":{  
          "key":"RO"
       },
       "body":{  
          "storage":{  
             "value":"<p>UPDATE This is a new page</p>",
             "representation":"storage"
          }
       },
       "version":{  
          "number":2
       }
    }
    

    Don't forget to use: