Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update confluence page using curl on a Jenkins job

Lalo Ascencio January 20, 2022

Hello community I've been trying to update a confluence page from a Jenkins job using curl. Below we can see the pipeline stage that is supposed to take care of it:

 

stage ('Publish Release Notes')
{
withCredentials([string(credentialsId: 'credentials', variable: 'ATL')]) {
sh(script: "curl -X PUT https://confluence.mycomp.com/rest/api/content/<pageid> -H 'Authorization: Basic ${ATL}' -H 'X-Atlassian-Token: no-check' -H 'Content-Type: application/json' -d @${workspace}/release_notes.json")
}
}

 

 

Below we can see the json file contents:

 

{"id":"<pageid>","type":"page","status":"current","version":{"number":5},"title":"Jenkins Connectivity Test","body":{"storage":{"value":"<ac:layout><ac:layout-section ac:type=\"single\"><ac:layout-cell><p>Second form</p></ac:layout-cell></ac:layout-section><ac:layout-section ac:type=\"two_equal\"><ac:layout-cell><p class=\"auto-cursor-target\"><br></br><br></br></p></ac:layout-cell><ac:layout-cell><p class=\"auto-cursor-target\"><br></br></p><p><br></br></p></ac:layout-cell></ac:layout-section></ac:layout>","representation":"storage","_expandable":{"content":"/rest/api/content/<pageid>"}},"_expandable":{"editor":"","view":"","export_view":"","styled_view":"","anonymous_export_view":""}},"extensions":{"position":"none"},"_links":{"webui":"/display/WKB/Jenkins+Connectivity+Test","edit":"/pages/resumedraft.action?draftId=262088613&draftShareId=42bb8fb1-e467-46d3-b1d0-8f61be65c6d8","tinyui":"/x/pSefDw","collection":"/rest/api/content","base":"https://confluence.ehi.com","context":"","self":"https://confluence.ehi.com/rest/api/content/<pageid>"},"_expandable":{"container":"/rest/api/space/WKB","metadata":"","operations":"","children":"/rest/api/content/<pageid>/child","restrictions":"/rest/api/content/<pageid>/restriction/byOperation","history":"/rest/api/content/262088613/history","ancestors":"","version":"","descendants":"/rest/api/content/<pageid>/descendant","space":"/rest/api/space/WKB"}}

 

 

The following error can be observed when run:

 

HTTP Status 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> Illegal base64 character 24</p><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: Illegal base64 character 24
19:49:53  	java.util.Base64$Decoder.decode0(Base64.java:714)
19:49:53  	java.util.Base64$Decoder.decode(Base64.java:526)
19:49:53  	java.util.Base64$Decoder.decode(Base64.java:549)
19:49:53  	com.atlassian.seraph.util.SecurityUtils.decodeBasicAuthorizationCredentials(SecurityUtils.java:49)
19:49:53  	com.atlassian.seraph.auth.DefaultAuthenticator.getUserFromBasicAuthentication(DefaultAuthenticator.java:510)
19:49:53  	com.atlassian.seraph.auth.DefaultAuthenticator.getUser(DefaultAuthenticator.java:341)
19:49:53  	com.atlassian.seraph.filter.SecurityFilter.doFilter(SecurityFilter.java:139)
19:49:53  	com.atlassian.confluence.web.filter.ConfluenceSecurityFilter.applyFilter(ConfluenceSecurityFilter.java:40)
19:49:53  	com.atlassian.confluence.web.filter.ConfluenceSecurityFilter.doFilter(ConfluenceSecurityFilter.java:29)

Please let me know what might be causing the issue. Credentials have been tested and they have necessary writing permissions.

Thanks and regards. 

2 answers

1 accepted

0 votes
Answer accepted
Lalo Ascencio January 28, 2022

I've solved my issue. My problem was my credentials had a character that CURL didn't like. In order to fix it without having to change my credentials I've created an encoded base64 string including "user:password". Once I did that I could connect supplying basic auth headers in the following form:

curl -X GET -H "Authorization: Basic <your_encoded_string>" -H "Content-Type: application/json" "https://<your-domain.atlassian.net>/wiki/rest/api/space"

More info can be reviewed here

1 vote
Pramodh M
Community Champion
January 20, 2022

Hi @Lalo Ascencio 

Welcome to the Community!!

Can you please try this solution which is working and let me know

https://community.atlassian.com/t5/Confluence-questions/I-am-getting-500-internal-server-error-when-trying-to-update-a/qaq-p/1912037

Thanks,
Pramodh

Lalo Ascencio January 21, 2022

Hello Pramodh,

 

Thank you very much for your response. I've tried that option in order to obtain the info using the following stage:

 

stage ('Get Release Notes')
{
withCredentials([string(credentialsId: 'do_middleware_artifactory', variable: 'ATL')]) {
sh(script: "curl -X GET 'https://confluence.mycomp.com/rest/api/content/262088613?expand=body.storage' -H 'Authorization: Basic ${ATL}' -H 'X-Atlassian-Token: no-check' -o ${workspace}/obtained_page.json")
}
}

 

The resulting file content for that is the following:

 

<!doctype html><html lang="en"><head><title>HTTP Status 500 ▒^▒^▒ Internal Server Error</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 ▒^▒^▒ Internal Server Error</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> Illegal base64 character 24</p><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: Illegal base64 character 24
java.util.Base64$Decoder.decode0(Base64.java:714)
java.util.Base64$Decoder.decode(Base64.java:526)

 

Pretty much the same as with the PUT method.

 

I've also tested directly from my unix AIX server:

$ [ do_middleware@host:/opt/do_middleware ]
# curl -X GET https://confluence.mycomp.com/rest/api/content/262088613?expand=body.storage -u do_middleware:"***********"
<!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Basic Authentication Failure - Reason : AUTHENTICATED_FAILED</p><p><b>Description</b> The request has not been applied because it lacks valid authentication credentials for the target resource.</p><hr class="line" /><h3>Apache Tomcat/9.0.45</h3></body></html>
$ [ do_middleware@tstapl18a:/opt/do_middleware ]
# curl -X GET https://confluence.mycomp.com/rest/api/content/262088613?expand=body.storage
{"statusCode":404,"data":{"authorized":false,"valid":true,"allowedInReadOnlyMode":true,"errors":[],"successful":false},"message":"No content found with id: ContentId{id=262088613}","reason":"Not Found"}

# curl -X GET "https://confluence.mycomp.com/rest/api/content/262088613?expand=body.storage" -u do_middleware:"*************"
<!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {col or:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-co lor:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Basic Authent ication Failure - Reason : AUTHENTICATION_DENIED</p><p><b>Description</b> The request has not been applied because it lacks valid authentication credentials for the ta rget resource.</p><hr class="line" /><h3>Apache Tomcat/9.0.45</h3></body></html>

As you can see from Jenkins I'm using a variable that it's supposed to contain the API Token (I did not create it as I lack enough permissions, it was already there). This credentials are stored as:

  • Secret text - a token such as an API token (e.g. a GitHub personal access token),

The resulting file from running the pipeline has a 500 error, is this enough to say that at least the credentials are correct and it connected to Confluence?

Seeing the tests from Unix it seems this user has no access, but when I connect through browser I'm able to write on that page:

do_middleware user edition.PNG

So I guess my issue could be related to me not using credentials properly

 

Sorry if my questions are too noob type.

Pramodh M
Community Champion
January 21, 2022

Hi @Lalo Ascencio 

I see that you are getting a 401 Unauthorized error when you are doing GET Request.

Can you make a manual request like this and let me know if it's working

Give the password which is used when logging in into confluence server

curl -u admin:password -X GET "http://localhost:8080/confluence/rest/api/content?title=myPage%20Title &spaceKey=TST&expand=history"

Let me know if this works!!

Thanks,
Pramodh

Lalo Ascencio January 21, 2022

Hi Pramodh,

 

It doesn't, because I do not count with the API Token, I only have the user/password. But I was told that the existing credentials stored in Jenkins would work. What I'm not sure is if they are of the API Token type. So, I'm on a point that I'm starting to doubt the credentials used in Jenkins are what I need, is there a way to be sure testing them?

 

Below we can see a couple of tests using my regular credentials (but no API Token):


bash-4.2$ curl -u eduardo.ascencio@ehi.com:"password" -X GET "https://confluence.ehi.com/rest/api/content?title=Jenkins%20Connectivity%20Test&spaceKey=TST&expand=history"
<!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Basic Authentication Failure - Reason : AUTHENTICATED_FAILED</p><p><b>Description</b> The request has not been applied because it lacks valid authentication credentials for the target resource.</p><hr class="line" /><h3>Apache Tomcat/9.0.45</h3></body></html>bash-4.2$

 

bash-4.2$ curl -u do_middleware:"password" -X GET "https://confluence.ehi.com/rest/api/content?title=Jenkins%20Connectivity%20Test&spaceKey=TST&expand=history" <!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Basic Authentication Failure - Reason : AUTHENTICATION_DENIED</p><p><b>Description</b> The request has not been applied because it lacks valid authentication credentials for the target resource.</p><hr class="line" /><h3>Apache Tomcat/9.0.45</h3></body></html>bash-4.2$

 

Regards.

Lalo Ascencio January 26, 2022

As you can see in my previous Screenshot I can connect  on UI (through browser) with same credentials but I can connect using CURL. That is why I think I may need to apply an additional step to my credentials. Can you confirm?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events