Confluence
The other samples in this section call the Jira REST API, but the request format is the same for Confluence. Only the url changes, because Confluence paths begin with /wiki.
See Making requests for the format.
curl
curl -X POST <YOUR ENDPOINT URL> --header "apikey: <YOURTOKEN>" --data '
{
"options": {
"method": "GET",
"headers": {
"Content-Type": "application/json",
"Accept": "application/json"
}
},
"url": "/wiki/rest/api/content?limit=10"
}'
Python
import requests
import json
endpointURL = "<YOUR ENDPOINT URL>"
r = requests.post(endpointURL, json={
"options": {
"method": "GET",
"headers": {
"Content-Type": "application/json",
"Accept": "application/json"
}
},
"url": "/wiki/rest/api/content?limit=10"
}, headers={"apikey": "<YOURTOKEN>"})
print("Status Code: ", r.status_code)
print("Response: ", json.dumps(r.json(), indent=2))
Node.js
import fetch from 'node-fetch';
const response = await fetch('<YOUR ENDPOINT URL>', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
apikey: '<YOURTOKEN>',
},
body: JSON.stringify({
options: {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
},
url: '/wiki/rest/api/content?limit=10',
}),
});
console.log('Status', response.status);
console.log(JSON.stringify(JSON.parse(await response.text()), null, 2));
Creating a page
{
"options": {
"method": "POST",
"headers": { "Content-Type": "application/json", "Accept": "application/json" },
"body": {
"type": "page",
"title": "Created through API Key Manager",
"space": { "key": "<SPACE KEY>" },
"body": {
"storage": { "value": "<p>Hello from a key.</p>", "representation": "storage" }
}
}
},
"url": "/wiki/rest/api/content"
}
This needs a key that allows POST and the endpoint /wiki/rest/api/content.