Confluence REST API question
Asked by sanan sanan:

Hi,

I give following in my browser url :

[https://confluence.ie/rest/api/space?type=site\&limit=500](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


Answers:
author: Pramodh M
body: Hi [@sanan sanan](/t5/user/viewprofilepage/user-id/1152151)

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

comments: author: sanan sanan
body: Hi, [@Pramodh M](/t5/user/viewprofilepage/user-id/3691224) ,

thanks for your reply.

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

Regards


author: sanan sanan
body: Hi, [@Pramodh M](/t5/user/viewprofilepage/user-id/3691224) ,

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


author: Pramodh M
body: Great! [@sanan sanan](/t5/user/viewprofilepage/user-id/1152151)

Happy to help :-)

Thanks,  
Pramodh


author: ss
body: anyone, who can help?


Tags: confluence-server

rest-api

server

space