# I want to get all the spaces in my kibana using python API

**URL:** https://discuss.elastic.co/t/i-want-to-get-all-the-spaces-in-my-kibana-using-python-api/327859
**Category:** Kibana
**Created:** [March 16, 2023, 2:06pm UTC](https://discuss.elastic.co/t/i-want-to-get-all-the-spaces-in-my-kibana-using-python-api/327859 "2023-03-16T14:06:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bhrugu\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhrugu_sharma/32/116623_2.png) [@Bhrugu\_Sharma](https://discuss.elastic.co/u/Bhrugu_Sharma)
#### Post date: [March 16, 2023, 2:06pm UTC](https://discuss.elastic.co/t/i-want-to-get-all-the-spaces-in-my-kibana-using-python-api/327859/1 "2023-03-16T14:06:43Z")

</div>

I am trying to write a python script to get all the spaces in my Kibana spaces I tried all the different combos but there seems to be no proper way for it.  
Here are the few examples that i tired  
`resp = client.api.spaces()`

`resp = client.spaces.space()`

any help would be appreciated

---

<div class="post-metadata">

### Author: ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)
#### Post date: [April 12, 2023, 4:24pm UTC](https://discuss.elastic.co/t/i-want-to-get-all-the-spaces-in-my-kibana-using-python-api/327859/2 "2023-04-12T16:24:54Z")

</div>

I can't help on the python side (which library are you using?) but you can definitely use the Kibana HTTP API directly to interact with Spaces

> **[Get all Kibana spaces API | Kibana Guide \[master\] | Elastic](https://www.elastic.co/guide/en/kibana/master/spaces-api-get-all.html)**
>
> Conceptual and step-by-step procedures for using runtime fields, scripted fields, and field formatters.

---

<div class="post-metadata">

### Author: ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)
#### Post date: [April 12, 2023, 5:08pm UTC](https://discuss.elastic.co/t/i-want-to-get-all-the-spaces-in-my-kibana-using-python-api/327859/3 "2023-04-12T17:08:42Z")

</div>

```auto
        url_space=f'http://{master}:5601/api/spaces/space'

        ## retrive all the spaces names from one master, 
        try:
            space_names = requests.get(url_space, auth=(elk_admin_user,elk_admin_password))
            space_names_array = space_names.json()
            
            for i in range(0,len(space_names_array)):

```

this will get you all the space names from that server.

---

<div class="post-metadata">

### Author: ![Bhrugu\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhrugu_sharma/32/116623_2.png) [@Bhrugu\_Sharma](https://discuss.elastic.co/u/Bhrugu_Sharma)
#### Post date: [April 12, 2023, 5:14pm UTC](https://discuss.elastic.co/t/i-want-to-get-all-the-spaces-in-my-kibana-using-python-api/327859/4 "2023-04-12T17:14:49Z")

</div>

I forgot this existed i was able to find the solution here it is

```auto
import requests
import json

# Replace with your Kibana URL and credentials
kibana_url = 'https://<kibana_url>/kibana'

headers = {
    'kbn-xsrf': 'true',
    'Content-Type': 'application/json',
    'Authorization': 'Basic <kibana_admin_token>'
}

# Get a list of all spaces in Kibana
spaces_url = f'{kibana_url}/api/spaces/space'
response = requests.get(spaces_url, headers=headers, verify=True)
spaces = response.json()

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 10, 2023, 5:15pm UTC](https://discuss.elastic.co/t/i-want-to-get-all-the-spaces-in-my-kibana-using-python-api/327859/5 "2023-05-10T17:15:44Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
