> 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/restrictions.md).

# Restrictions

## Get restrictions

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

Returns the restrictions on a piece of content.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"fmt"
	"github.com/ctreminiom/go-atlassian/confluence"
	"log"
	"net/http"
	"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")

	restrictions, response, err := instance.Content.Restriction.Gets(context.Background(), "80412692", []string{"restrictions.user", "restrictions.group"}, 0, 50)
	if err != nil {
		if response != nil {
			if response.Code == http.StatusBadRequest {
				log.Println(response.Code)
			}
		}
		log.Fatal(err)
	}

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

	for _, restriction := range restrictions.Results {

		if restriction.Restrictions.Group != nil {
			for _, group := range restriction.Restrictions.Group.Results {
				fmt.Println(restriction.Operation, group.Name)
			}
		}

		if restriction.Restrictions.User != nil {
			for _, user := range restriction.Restrictions.User.Results {
				fmt.Println(restriction.Operation, user.Email, user.AccountID, user.AccountType)
			}
		}
	}

}
```

{% endcode %}

## Add Restrictions

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

Adds restrictions to a piece of content. Note, this does not change any existing restrictions on the content.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"fmt"
	"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")
	)

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

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

	payload :=  &models.ContentRestrictionUpdatePayloadScheme{
		Results: []*models.ContentRestrictionUpdateScheme{
			{
				Operation: "update",
				Restrictions: &models.ContentRestrictionRestrictionUpdateScheme{
					Group: []*models.SpaceGroupScheme{
						{
							Type: "group",
							Name: "jira-users-22",
						},
					},
					User: []*models.ContentUserScheme{
						{
							AccountID:      "5e5f6acefc1fca0af44135f8",
						},
					},
				},
			},
		},
	}

	contentID := "80412692"
	expand := []string{"restrictions.user", "restrictions.group", "content"}
	ctx := context.Background()

	restrictions, response, err := instance.Content.Restriction.Add(ctx, contentID, payload, expand)
	if err != nil {
		if response != nil {
			log.Println(response.Code)
			log.Println("Endpoint:", response.Endpoint)
		}
		log.Fatal(err)
	}

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

	for _, restriction := range restrictions.Results {

		if restriction.Restrictions.Group != nil {
			for _, group := range restriction.Restrictions.Group.Results {
				fmt.Println(restriction.Operation, group.Name)
			}
		}

		if restriction.Restrictions.User != nil {
			for _, user := range restriction.Restrictions.User.Results {
				fmt.Println(restriction.Operation, user.Email, user.AccountID, user.AccountType)
			}
		}
	}
}
```

{% endcode %}

## Update Restrictions

`PUT /wiki/rest/api/content/{id}/restriction`

Updates restrictions for a piece of content. This removes the existing restrictions and replaces them with the restrictions in the request.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"fmt"
	"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")
	)

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

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

	payload :=  &models.ContentRestrictionUpdatePayloadScheme{
		Results: []*models.ContentRestrictionUpdateScheme{
			{
				Operation: "update",
				Restrictions: &models.ContentRestrictionRestrictionUpdateScheme{
					Group: []*models.SpaceGroupScheme{
						{
							Type: "group",
							Name: "jira-users-22",
						},
					},
				},
			},
		},
	}

	contentID := "80412692"
	expand := []string{"restrictions.user", "restrictions.group", "content"}
	ctx := context.Background()

	restrictions, response, err := instance.Content.Restriction.Update(ctx, contentID, payload, expand)
	if err != nil {
		if response != nil {
			log.Println(response.Code)
			log.Println("Endpoint:", response.Endpoint)
		}
		log.Fatal(err)
	}

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

	for _, restriction := range restrictions.Results {

		if restriction.Restrictions.Group != nil {
			for _, group := range restriction.Restrictions.Group.Results {
				fmt.Println(restriction.Operation, group.Name)
			}
		}

		if restriction.Restrictions.User != nil {
			for _, user := range restriction.Restrictions.User.Results {
				fmt.Println(restriction.Operation, user.Email, user.AccountID, user.AccountType)
			}
		}
	}
}
```

{% endcode %}

## Delete Restrictions

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

Removes all restrictions (read and update) on a piece of content.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"fmt"
	"github.com/ctreminiom/go-atlassian/confluence"
	"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")

	contentID := "80412692"
	expand := []string{"restrictions.user", "restrictions.group", "content"}
	ctx := context.Background()

	restrictions, response, err := instance.Content.Restriction.Delete(ctx, contentID, expand)
	if err != nil {
		if response != nil {
			log.Println(response.Code)
			log.Println("Endpoint:", response.Endpoint)
		}
		log.Fatal(err)
	}

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

	for _, restriction := range restrictions.Results {

		if restriction.Restrictions.Group != nil {
			for _, group := range restriction.Restrictions.Group.Results {
				fmt.Println(restriction.Operation, group.Name)
			}
		}

		if restriction.Restrictions.User != nil {
			for _, user := range restriction.Restrictions.User.Results {
				fmt.Println(restriction.Operation, user.Email, user.AccountID, user.AccountType)
			}
		}
	}
}
```

{% 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/restrictions.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.
