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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.