Basic Authentication on Confluence Cloud REST API not working

I’m trying to use the Basic Auth REST API for Confluence cloud documented here:
https://developer.atlassian.com/cloud/confluence/rest/

Also my username in Confluence is “Admin”, will this cause problems?

However, I’m unable to authenticate as myself when I issue this request:

curl -X GET \
   --user '<my-email-address>:<my-api-token>' \
   -H 'Cache-Control: no-cache' \
   -H 'Accept: application/json' \
   -H "Content-Type: application/json" \
   "https://<my-domain>.atlassian.net/wiki/rest/api/user/current"

This is the response I get (verbose from curl):

> GET /wiki/rest/api/user/current HTTP/2
> Host: <domain>.atlassian.net
> Authorization: Basic <base64 string>
> User-Agent: curl/7.54.0
> Cache-Control: no-cache
> Accept: application/json
> Content-Type: application/json
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 401
< server: Atlassian Proxy/0.1.205
< vary: Accept
< www-authenticate: OAuth realm="https%3A%2F%2F<domain>.atlassian.net%2Fwiki"
< cache-control: no-cache, must-revalidate
< content-type: application/json
< strict-transport-security: max-age=315360000; includeSubDomains; preload
< date: Thu, 22 Mar 2018 22:40:54 GMT
< expires: Thu, 01 Jan 1970 00:00:00 GMT
< x-xss-protection: 1; mode=block
< x-content-type-options: nosniff
<
* Connection #0 to host <domain>.atlassian.net left intact
{"message":"Request rejected because issuer is either not authorized or not authorized to impersonate","status-code":401}

My Atlassian ID is linked to my Google account and has two factor auth turned on. I’m not sure if that matters here.

Interestingly enough, this curl request works (note that it’s using the Authentication header, not Authorization). However, it Authenticates me as an anonymous user which is not what I would expect given that I’ve sent in my username and API token in the base64 encoded string.

curl -v -X GET \
   -H 'Authentication: Basic <base64 encoded credentials>' \
   -H 'Cache-Control: no-cache' \
   -H 'Accept: application/json' \
   -H "Content-Type: application/json" \
   "https://<domain>.atlassian.net/wiki/rest/api/user/current"

> GET /wiki/rest/api/user/current HTTP/2
> Host: <domain>.atlassian.net
> User-Agent: curl/7.54.0
> Authentication: Basic <base64 encoded string>
> Cache-Control: no-cache
> Accept: application/json
> Content-Type: application/json
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200
< server: Atlassian Proxy/0.1.205
< vary: Accept-Encoding
< cache-control: no-cache, must-revalidate
< content-type: application/json
< strict-transport-security: max-age=315360000; includeSubDomains; preload
< date: Thu, 22 Mar 2018 22:46:39 GMT
< expires: Thu, 01 Jan 1970 00:00:00 GMT
< x-xss-protection: 1; mode=block
< x-content-type-options: nosniff
<
* Connection #0 to host <domain>.atlassian.net left intact
{"type":"anonymous","profilePicture":{"path":"/wiki/s/<some path>/anonymous.png","width":48,"height":48,"isDefault":true},"displayName":"Anonymous","_expandable":{"operations":""},"_links":{"base":"https://<domain>.atlassian.net/wiki","context":"/wiki"}}

Hi @jeff3,

“admin” as username should not cause you a problem. However, in your curl request:

are you using your email address and your api token in the --user argument? I’ve tried now and was able to get a response.

Cheers,
Anne Calantog

1 Like

I’m facing the exact same problem:

curl \
    --user <my_email>:<my_api_token> \                                                                                                                                    (1s 17ms)
    --header 'Accept: application/json' \
    --url 'https://<my_site>.atlassian.net/wiki/rest/api/content'

Yields a 401

{"message":"Request rejected because issuer is either not authorized or not authorized to impersonate","status-code":401}⏎

My Atlassian ID is also a linked Google account.

Is there a configuration somewhere that disables Confluence REST API?

Hi @huy,

Not that I’m aware of. Your command is correct and that should work for you as is mine. I tested now and I got a response from it.

If you’re currently logged in your your instance via browser, can you try navigating to: https://.atlassian.net/wiki/rest/api/content and see what happens?

Cheers,
Anne Calantog

2 Likes

Hi @huy, did you found out about Rest Api with Google?
I tried curl like so because npm start on my project thrown not authorized to impersonate as well

1 Like