The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

where to write API's in confluence??

Vidya Shevale
October 16, 2018

I want to write API's in confluence

but I am getting confused where to write it.

I am using ubuntu 16.04 and my confluence is installed in  /opt/atlassian 

also there is one more folder in /var/atlassian

now I am writing api's using php which are located in /var/www/html/confluence_api

<?php
$data = {
"type":"page",
"title":"My Test Page",
"space":{"key":"TST"},
"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}
};
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://localhost:8090/rest/api/content/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "*****" . ":" . "*****");

$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
print_r($result);
?>

and I am using POST method for calling the API  but I am getting  404 http_code in return 

GET method is working fine but not POST

please answer me ASAP

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 16, 2018

I'm not even sure how you came up with the idea of wedging bits of code in the wrong language into Confluence is a good idea.

If you want to add new APIs to Confluence, you should write the end points in Java in an App you add to Confluence.

If you want to use the APIs in Confluence, you can use php (or other languages), but do not put your code inside the Confluence installation, that can break all sorts of things.

The content call you are using expects to be a get, not a post, that's why you get a 404.

Vidya Shevale
October 16, 2018

hey thanks @Nic Brough -Adaptavist- for your reply

my requirement is PHP so I am writing APi's in php language. I created separate folder for api's and not in the confluence setup.

now working it is as expected

thanks

  

TAGS
AUG Leaders

Atlassian Community Events