Php confluence api

HI,

iam using rest api to get spaces list from confluence using php curl . But iam getting the error .please check my code

 

$url = "https://xxxxxxx.atlassian.net/rest/api/space?spaceKey=xxx";
 
$ch = curl_init();
 
$headers = array(
 
    'Accept: application/json',
 
    'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx'        // this is the oauth token
 
);
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
curl_setopt($ch, CURLOPT_VERBOSE, 1);
 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

curl_setopt($ch, CURLOPT_URL, $url);
 
$result = curl_exec($ch);
 
$ch_error = curl_error($ch);
 
if ($ch_error) {
 
    echo "cURL Error: $ch_error";
 
} else {
 
    echo $result;
 
}  
 
curl_close($ch);

 

Response is {"error": "Failed to parse Connect Session Auth Token"}

1 answer

0 vote

The token is incorrect, you'll need to fix that.  It's the Authorisation line, but I can't tell you what's wrong with it as I don't know what php does with it exactly.

Replaced my original token with xxxxxx for security purpose . Can you please show me the example on how to use authorisation line ?

I am sorry, I was not clear.  I had assumed the xxx were obscuring the actual data.  What I'm trying to say is that there is something wrong with the token in there.  I can't tell you whether it's a bad token because I don't know how you've generated, or if it is something php is doing with it that makes it broken for Confluence.

Hi Sampath, if you have fixes for this issue... Please share... I am also facing the same problem...

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Published 12 hours ago in Confluence

Think you know shares vs. @mentions in Confluence? Take this collab quiz.

To anyone who doubts that Atlassians are a little too obsessed with collaboration, and tools related thereto, let me describe a recent discussion we had (which took place on our internal Confluence, ...

95 views 2 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you