# Space

The Confluence Cloud V2 API space endpoints are a set of new features and functionalities that have been introduced in the Confluence Cloud platform to provide users with enhanced control and management of their Confluence spaces. These endpoints allow users to perform various space-related operations programmatically, such as creating new spaces, updating space properties, retrieving space information, and managing space permissions.

## Get spaces

`GET /wiki/api/v2/spaces`

Bulk returns all spaces. The results will be sorted by id ascending. The number of results is limited by the `limit` parameter and additional results (if available) will be available through the `next` URL present in the `Link` response header.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"fmt"
	confluence "github.com/ctreminiom/go-atlassian/confluence/v2"
	"github.com/ctreminiom/go-atlassian/pkg/infra/models"
	"log"
	"net/url"
	"os"
)

func main() {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	instance, err := confluence.New(nil, host)
	if err != nil {
		log.Fatal(err)
	}

	instance.Auth.SetBasicAuth(mail, token)
	instance.Auth.SetUserAgent("curl/7.54.0")

	options := &models.GetSpacesOptionSchemeV2{
		IDs:               nil,
		Keys:              nil,
		Type:              "",
		Status:            "",
		Labels:            nil,
		Sort:              "",
		DescriptionFormat: "",
		SerializeIDs:      false,
	}

	var cursor string
	for {

		spaces, response, err := instance.Space.Bulk(context.Background(), options, cursor, 20)
		if err != nil {
			log.Fatal(err)
		}

		for _, space := range spaces.Results {
			fmt.Println(space)
		}

		log.Println("Endpoint:", response.Endpoint)
		log.Println("Status Code:", response.Code)

		if spaces.Links.Next == "" {
			break
		}

		values, err := url.ParseQuery(spaces.Links.Next)
		if err != nil {
			log.Fatal(err)
		}

		_, containsCursor := values["cursor"]
		if containsCursor {
			cursor = values["cursor"][0]
		}
	}
}
```

{% endcode %}

## Get space by id

`GET /wiki/api/v2/spaces/{id}`

Get returns a specific space.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"fmt"
	confluence "github.com/ctreminiom/go-atlassian/confluence/v2"
	"log"
	"os"
)

func main() {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	instance, err := confluence.New(nil, host)
	if err != nil {
		log.Fatal(err)
	}

	instance.Auth.SetBasicAuth(mail, token)
	instance.Auth.SetUserAgent("curl/7.54.0")

	space, response, err := instance.Space.Get(context.Background(), 196613, "plain")
	if err != nil {
		if response != nil {
			log.Println(response.Bytes.String())
		}

		log.Fatal(err)
	}
	fmt.Println(space)
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.go-atlassian.io/confluence-cloud/v2/space.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
