API REST on Confluence SERVER (not Cloud) : getting 401 authorization failed

Romain Lafond September 19, 2019

Hi,

Often, I succed to find a solution to my problem via forums and internet. But, this time I'm stuck and I decided to share my problem because I think it could be useful for others confluence developers.

Environnement :

  • Confluence SERVER (not Cloud)
  • Presently, it's the first use of REST API for me

 

What I want to do ? Create a page from a website via a Restful call.

A POST call to "https://confluence.etsmtl.ca/rest/api/content/"

I installed the REST API Browser on Confluence Server.

I succed to call and create the page I wanted (see below).

REST API Browser.JPG

Then, I tried to use the same call from a different url (not from the same url of the confluence site). For that, I used ARC (Google Chrome pluggin).

When I send the call, I received a 401 - Unauthorized .

  • Basic Authentication Failure - Reason : AUTHENTICATED_FAILED
  • The request has not been applied because it lacks valid authentication credentials for the target resource.

 

401.JPG

What is my code ?

POST /rest/api/content/ HTTP/1.1
HOST: confluence.etsmtl.ca
content-type: application/json
status: current
authorization: Basic XXXXXXXXXXXXXXXX
content-length: 200

{"type":"page","title":"----P1.new page(GUS vers Confluence)","space":{"key":"~romain.lafond@etsmtl.ca"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}

where XXXXX is myusername:mypassword in base64.

My username is the username in my profil (not my email).

Each time, I sent the request, I received 401 AUTHORIZATION FAILED, after 3 times, it became a 401 AUTHORIZATION  DENIED.

In Confluence, on my user profile (sorry it's in French), my current number of connection failures is increasing each time i try. So, I understand, my username is correct.

Se connecter

  • Dernière connexion: sept. 19, 2019 09:34
  • Dernier échec de connexion: sept. 19, 2019 09:33
  • Nombre total d'échecs de connexion: 47
  • Nombre actuel d'échecs de connexion: 3

 

Next ? I red that basic authentification is deprecated but only for Cloud Confluence.

 

So, i'm stuck, I don't know which lead i could follow, If you have an idea to share, don't hesitate :-)

Thanks a lot to read me and if you have an idea, you are my hero !

 

Romain L.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events