Can't make curl access corporate confluence pages using API token (Basic auth works)

Kelly Maurice March 20, 2024

I'm having this problem. We have self-hosted confluence at my company. Basic authentication works with curl and username/pw:

curl -D- -u <username>:<password> -X GET -H "Content-Type: application/json" <confluence page to browse>

However, after getting a new API token from confluence website and substituting for the password:

curl -D- -u <username>:<API token> -X GET -H "Content-Type: application/json" <confluence page to browse>

it doesn't work - I get a 401 response and the following message included with other stuff:

Basic Authentication Failure - Reason : AUTHENTICATED_FAILED</p><p><b>Description</b> The request has not been applied to the target resource because it lacks valid authentication credentials for that resource.

It's curious that is used the words Basic Authentication Failure since I'm trying now to use API token and not Basic anymore.

I see answers online about:
- using network name instead of username
- leaving username blank (somehow)
- using email instead of username (for Basic authorization only username works, not email)

But these don't seem to work (and I don't know how to get my network username)

1 answer

0 votes
Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2024

Hi @Kelly Maurice 

Please can you share the API that you're using?

I tried this API and it works with the <username>:<API token> combination

Documentation :

Kelly Maurice March 27, 2024

Hi Jehan. In fact, I made it work on ubuntu, including remote ubuntu in a docker image. But it doesn't work on Windows. That's where I was stuck.

I am a little confused about which API to use: whether to use Server Confluence REST API or Cloud Conference REST API (and which version). I believe we host our own confluence at Here Technologies where I work. This is the command I used that worked on Ubuntu:

curl -u <Here username:password> -X POST -H 'Content-Type:application/json' -d '{"type":"page","title":"testing_curl_ubuntu","ancestors":[{"id":1949495409}],"space":{"key":"OneMapDev"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}'

So, that initial step worked on Linux but the next thing I am stuck on is trying to write the new page with content that includes an image (not as an attachment). It quietly fails and says  

Oops - an error has occurred

logo System Error 

But it doesn't add the page.

I modified the working initial command to create the blank page, and came up with this:

curl -u username:pw -X POST -H 'Content-Type:application/json' -H 'Accept: application/json' -d '{"type":"page","title":"Sample_Page_With_Images","ancestors":[{"id":1949495409}],"space":{"key":"OneMapDev"},"body":{"storage":{"value":"<p>This is a new page</p><ac:image><ri:attachment ri:filename=\"sino.png\","representation":"storage"}}}'

So, again I have the parent page underneath which I want to write a new child page. This parent is specified as an ID (1949495409). I basically tweaked my previous command to simply add the image (sino.png). But the ri:attachment seems to indicate it is trying to attach something. I only want to write the image directly into the doc as a rendered image.

I based this code on a different form of the command I found in:



Kelly Maurice March 27, 2024

The command was slightly wrong (no closing </ac:image>) but it didn't help:

curl -u username:pw -X POST -H 'Content-Type:application/json' -H 'Accept: application/json' -d '{"type":"page","title":"Sample_Page_With_Images","ancestors":[{"id":1949495409}],"space":{"key":"OneMapDev"},"body":{"storage":{"value":"<p>This is a new page</p><ac:image><ri:attachment ri:filename=\"sino.png\" /></ac:image>,"representation":"storage"}}}'

Some error details are given below:


Exception ID: 7f2f8d55-4656-4d1c-91e5-5fc0329799e0

Referer URL


Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events