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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,074
Community Members
 
Community Events
176
Community Groups

How to login to confluence using REST API

Hi,

For Login,
* In JIRA, API there is POST /rest/auth/1/session
* In Confluence, is there something similar equivalent API for confluence login ?

We couldn't find in Confluence REST API browser or in documentation. Just wondering how to get this.

I am planning to use VBA to communicate with confluence using confluence rest APIs to post the  data we have generated on the macro enabled(.xlsm)  excel workbook.

This is required for our activities to login & upload content

Appreciate if any advise/suggestions

3 answers

1 accepted

1 vote
Answer accepted

or you can pass a header with a bearer token. example for cURL

-H "Authorization: Bearer <your personal access token>"

 

there is more info at:

https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html

I am behind a corporate proxy so the solution above didn't work for me, what I needed to do is to log in first, save the JSESSIONID as a cookie and then use it in subsequent calls. 

This is a basic example in python

import json
import httplib2
import urllib

get_url = "https://<your confluence url>/rest/api/content/<your page id>?expand=body.storage"
login_url = "https://<your confluence url>/dologin.action"
username = "<your user name here>"
password = "<your password>"

h = httplib2.Http(".cache")

headers = {'Content-type': 'application/x-www-form-urlencoded'}
body={'os_username': username, 'os_password': password}
resp, content = h.request(
uri=login_url,
method='POST',
headers = headers,
body=urllib.urlencode(body)
)
cookies = resp.get("set-cookie")
headers = {'Cookie': cookies}

response, content = h.request(get_url, 'GET', headers=headers)

obj = json.loads(content)
print (obj['body']['storage']['value'])

Hello @David Caballero ,

 

Your way worked for me.

Do you know how I can make script to update a page everyday and write content to it using a script?

Thanks

1 vote

Hello,

I also did not find such REST call. But you can pass authentication in headers. Yes, you would pass it with every REST call but it would do the job.

Hi Alexey,

Thanks for the reply, can you please suggest the confluence login API for this.

That is example for the JQUERY

//This creates a page in a space.
var username = "admin";
var password = "admin";
var jsondata = {"type":"page",
 "title":"My Test Page",
 "space":{"key":"TST"},
 "body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}};
  
$.ajax
  ({
    type: "POST",
    url: "http://localhost:8080/confluence/rest/api/content/",
    contentType:"application/json; charset=utf-8",
    dataType: "json",
    async: false,
    headers: {
        "Authorization": "Basic " + btoa(username+ ":" + password)
    }, 
    data: JSON.stringify(jsondata),
    success: function (){
        console.log('Page saved!'); 
    },
    error : function(xhr, errorText){
  console.log('Error '+ xhr.responseText);
 }
});

You can read more here

https://developer.atlassian.com/confdev/confluence-server-rest-api/confluence-rest-api-examples 

Like Zhou TK likes this

Not so nice solution... If you make a lot of requests in high frequency, Confluence will probably get problems to perform all the authentication requests... So, most probably at some point Confluence authentication will fail and the user will need to enter CAPTCHA in the end. And for an automated user this is a problem.

Like Yadunandan likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events