Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

CURL solution to update confluence page

Alec Jasanovsky October 23, 2019

I haven't gotten to use the Confluence cloud API at all and figured someone may have a working example of a CURL command that updates a confluence page? 

 

Specifically, I want to add an Issue Filter Macro and apply a JQL. 

 

 

2 answers

1 accepted

1 vote
Answer accepted
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 8, 2019

Hello Alec,

Happy to help with that! First, you'll need to generate an API token if you haven't already.

You can find an example of the call you need from our documentation below:

According to this, your cURL command would be:

 curl -u <EMAIL>:<API_TOKEN> -H 'Content-Type: application/json' -d '<REQUEST_BODY_HERE>' -X PUT https://<NAME>.atlassian.net/wiki/rest/api/content/<PAGE-ID> 
Your request body (REQUEST_BODY_HERE above) can be sourced from a file. Here's an example of a request body for this:
 {
 "id": "CONTENT_ID_FROM_PAGE_URL",
 "type": "page",
 "title": "PAGE_TITLE",
 "version": {
   "number": (CURRENT_PAGE_VERSION_PLUS_1)
 },
 "space": {
   "key": "SPACE_KEY"
 },
 "body": {
   "storage": {
     "value": "<p><ac:structured-macro ac:name=\"jira\" ac:schema-version=\"1\" ac:macro-id=\"2522710c-30ab-4f0d-ad7b-f3beb63728a4\"><ac:parameter ac:name=\"server\">System JIRA</ac:parameter><ac:parameter ac:name=\"columns\">key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution</ac:parameter><ac:parameter ac:name=\"maximumIssues\">20</ac:parameter><ac:parameter ac:name=\"jqlQuery\">project=TRP </ac:parameter><ac:parameter ac:name=\"serverId\">f2a1787f-9df0-35e5-adf4-7167694a8392</ac:parameter></ac:structured-macro></p>",
     "representation": "storage"
   }
 }
}

Above, the "macro ID" and "server ID" are generated per instance. If you're not sure what your macro ID and server ID are, then you can insert a Jira Issues Macro in a page in Confluence manually, and then view the Storage Format (... > View Storage Format) in order to obtain that information for the future.

Additionally, you could call https://<NAME>.atlassian.net/wiki/rest/api/content/<PAGE-ID>?expand=body.storage and obtain the information in the same way.

Let me know if you have any trouble with that.

Regards,

Shannon

Alec Jasanovsky November 11, 2019

Thank you! I'll try that today!

Like Shannon S likes this
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 12, 2019

Alec,

You're welcome! Please let us know if it works for you or if you have any other questions or issues.

Regards,

Shannon

Nikhilesh Saggere December 7, 2020

Hi Shannon,

Could you please help i am using the below command (with reference to the above example), but i am getting the internal server error:

curl -u USER:"PASSKEY" -H "Content-Type:application/json" -d '{"id":"135769759","type":"page","title":"Configuration Management Plan","version":{"number":2},"space":{"key":"THEFW"},"body":{"storage":{"value":"<p>This is the updated text for the CMP page</p>","representation":"storage"}}' -X PUT https://confluence.sw.mycompany.com/rest/api/content/135769759 | python -mjson.tool


% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 257 0 64 100 193 64 193 0:00:01 0:00:01 --:--:-- 252
{
"statusCode": 500,
"message": "",
"reason": "Internal Server Error"
}
0 votes
Nikhilesh Saggere December 9, 2020

I am able to resolve the error, but the content in the confluence page seems to be not getting updated.

Command Used:

curl -H 'Content-Type:application/json' -X PUT -d '{"version:"{"number":2},"title":"Configuration Management Plan new","type":"page","body":{"storage":{"value":"<p>This is the updated text for the CMP page</p>","representation":"storage"}}}' https://confluence.sw.mycompany.com/rest/api/content/135769759 -u USER:"PASSKEY" 

The commands succeeds, but the page doesn't get updated.

Please help 

Lalo Ascencio January 26, 2022

Hi Nikhilesh, were you able to fix it?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events