Confluence REST API question

sanan sanan February 3, 2021

Hi,

I give following in my browser url :

https://confluence.ie/rest/api/space?type=site&limit=500

It gives me the list of all the spaces with many fields like key, name, type, id. 

I need only the names and keys of all the spaces. How can I filter it to receive only the names and keys of all the spaces?

Regards

2 answers

1 accepted

0 votes
Answer accepted
Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 4, 2021

Hi @sanan sanan 

Use the jq command-line tool to extract the data.

You have to use curl request via command line.

For Example, I have a response here as follows

{
"results": [
{
"id": 117964808,
"key": "GHS",
"name": "GitHub Space",
"type": "global",
"status": "current",
"_expandable": {
"settings": "/rest/api/space/GHS/settings",
"metadata": "",
"operations": "",
"lookAndFeel": "/rest/api/settings/lookandfeel?spaceKey=GHS",
"identifiers": "",
"permissions": "",
"icon": "",
"description": "",
"theme": "/rest/api/space/GHS/theme",
"history": "",
"homepage": "/rest/api/content/117965009"
},
"_links": {
"webui": "/spaces/GHS",
"self": "https://octowinner.atlassian.net/wiki/rest/api/space/GHS"
}
},
{
"id": 163841,
"key": "GS",
"name": "Glow Space",
"type": "global",
"status": "current",
"_expandable": {
"settings": "/rest/api/space/GS/settings",
"metadata": "",
"operations": "",
"lookAndFeel": "/rest/api/settings/lookandfeel?spaceKey=GS",
"identifiers": "",
"permissions": "",
"icon": "",
"description": "",
"theme": "/rest/api/space/GS/theme",
"history": "",
"homepage": "/rest/api/content/163842"
},
"_links": {
"webui": "/spaces/GS",
"self": "https://octowinner.atlassian.net/wiki/rest/api/space/GS"
}
},
{
"id": 81952770,
"key": "JO",
"name": "JSM One",
"type": "global",
"status": "current",
"_expandable": {
"settings": "/rest/api/space/JO/settings",
"metadata": "",
"operations": "",
"lookAndFeel": "/rest/api/settings/lookandfeel?spaceKey=JO",
"identifiers": "",
"permissions": "",
"icon": "",
"description": "",
"theme": "/rest/api/space/JO/theme",
"history": "",
"homepage": "/rest/api/content/81952900"
},
"_links": {
"webui": "/spaces/JO",
"self": "https://octowinner.atlassian.net/wiki/rest/api/space/JO"
}
},
{
"id": 360456,
"key": "~469932490",
"name": "Pramodh Kumar M",
"type": "personal",
"status": "current",
"_expandable": {
"settings": "/rest/api/space/~469932490/settings",
"metadata": "",
"operations": "",
"lookAndFeel": "/rest/api/settings/lookandfeel?spaceKey=~469932490",
"identifiers": "",
"permissions": "",
"icon": "",
"description": "",
"theme": "/rest/api/space/~469932490/theme",
"history": "",
"homepage": "/rest/api/content/360528"
},
"_links": {
"webui": "/spaces/~469932490",
"self": "https://octowinner.atlassian.net/wiki/rest/api/space/~469932490"
}
}
],
"start": 0,
"limit": 25,
"size": 4,
"_links": {
"base": "https://octowinner.atlassian.net/wiki",
"context": "/wiki",
"self": "https://octowinner.atlassian.net/wiki/rest/api/space"
}
}

So after the curl request like this

curl --request GET --url 'https://octowinner.atlassian.net/wiki/rest/api/space' --user 'username:token' --header 'Accept: application/json' 

Append the jq command like this

curl --request GET --url 'https://octowinner.atlassian.net/wiki/rest/api/space' --user 'username:token' --header 'Accept: application/json' | jq '.results[] | {name:.name, key:.key, id:.id}'

Please let me know if you have any questions

Thanks,
Pramodh

sanan sanan February 5, 2021

Hi, @Pramodh M ,

 

thanks for your reply. 

I will try this suggestion and get back to you soon.

Regards

Like Pramodh M likes this
sanan sanan February 5, 2021

Hi, @Pramodh M ,

Your suggestion has actually done the work. 

Installing jq was also just a piece of cake.

I have now got the list of what I wanted. 

You are a community leader for a reason. :)

Regards

Like # people like this
Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 5, 2021

Great! @sanan sanan 

Happy to help :-)

Thanks,
Pramodh

0 votes
ss February 4, 2021

anyone, who can help?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events