> For the complete documentation index, see [llms.txt](https://docs.go-atlassian.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.go-atlassian.io/confluence-cloud/content/labels.md).

# Labels

## Get labels for content

`GET /wiki/rest/api/content/{id}/label`

{% hint style="info" %}
Deprecated, use [Confluence's v2 API](/confluence-cloud/v2.md).
{% endhint %}

Returns the labels on a piece of content.

{% code fullWidth="true" %}

```go
package main

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

func main()  {

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

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

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

   var (
      contentID = "80412692"
      prefix = ""
      startAt = 0
      maxResults = 50
   )

   labels, response, err := atlassian.Content.Label.Gets(context.Background(), contentID, prefix, startAt, maxResults)
   if err != nil {
      log.Println(response.Endpoint)
      log.Println(response.Bytes.String())
      log.Fatal(err)
   }


   for _, label := range labels.Results {
      log.Println(label)
   }
}
```

{% endcode %}

## Add labels to content

`POST /wiki/rest/api/content/{id}/label`

Adds labels to a piece of content. It does not modify the existing labels.

* Labels can also be added when creating content ([Create content](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-labels/)).
* Labels can be updated when updating content ([Update content](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-labels/)). This will delete the existing labels and replace them with the labels in the request.

{% code fullWidth="true" %}

```go
package main

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

func main()  {

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

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

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

	var (
		contentID = "80412692"
		payload = []*models.ContentLabelPayloadScheme{
			{
				Prefix: "global",
				Name:   "label-02",
			},
		}
	)

	labels, response, err := atlassian.Content.Label.Add(context.Background(), contentID, payload, false)
	if err != nil {
		log.Println(response.Endpoint)
		log.Println(response.Bytes.String())
		log.Fatal(err)
	}

	for _, label := range labels.Results {
		log.Println(label)
	}
}
```

{% endcode %}

## Remove label from content

`DELETE /wiki/rest/api/content/{id}/label/{label}`

Removes a label from a piece of content. This is similar to [Remove label from content using query parameter](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-labels/) except that the label name is specified via a path parameter.

{% code fullWidth="true" %}

```go
package main

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

func main()  {

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

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

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


   response, err := atlassian.Content.Label.Remove(context.Background(), "80412692", "label-02")
   if err != nil {
      log.Println(response.Endpoint)
      log.Println(response.Bytes.String())
      log.Fatal(err)
   }
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.go-atlassian.io/confluence-cloud/content/labels.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
