Skip to content

Add to group

POST/directory/user-groups/{groupId}/users

Common API · Directory Management

Add multiple users to the specified group.

Required permissiontenant-directory.membership:add

Parameters

Name In Type Required Description
X-Tenant-ID header string (uuid) Yes Tenant ID.
groupId path string (uuid) Yes Group ID.

Request body

Content type: application/json

Request body fields

idsarray of string (uuid)required
List of user IDs.
Must contain at most 1000 items. Items must be unique.

Request samples

curl -X POST "https://api-<data-region>.central.sophos.com/common/v1/directory/user-groups/<groupId>/users" -H "Authorization: Bearer <access-token>" -H "X-Tenant-ID: <tenant-id>" -H "Content-Type: application/json" -d "{
  \"ids\": [
    \"3fa85f64-5717-4562-b3fc-2c963f66afa6\"
  ]
}"

import requests

response = requests.post(
    "https://api-<data-region>.central.sophos.com/common/v1/directory/user-groups/<groupId>/users",
    headers={
        "Authorization": "Bearer <access-token>",
        "X-Tenant-ID": "<tenant-id>",
        "Content-Type": "application/json",
    },
    json={'ids': ['3fa85f64-5717-4562-b3fc-2c963f66afa6']},
)
print(response.json())

$headers = @{
    "Authorization" = "Bearer <access-token>"
    "X-Tenant-ID" = "<tenant-id>"
    "Content-Type" = "application/json"
}
$body = '{
  "ids": [
    "3fa85f64-5717-4562-b3fc-2c963f66afa6"
  ]
}'
Invoke-RestMethod -Method POST -Uri "https://api-<data-region>.central.sophos.com/common/v1/directory/user-groups/<groupId>/users" -Headers $headers -Body $body -ContentType "application/json"

package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    req, err := http.NewRequest("POST", "https://api-<data-region>.central.sophos.com/common/v1/directory/user-groups/<groupId>/users", strings.NewReader(`{
  "ids": [
    "3fa85f64-5717-4562-b3fc-2c963f66afa6"
  ]
}`))
    if err != nil {
        panic(err)
    }
    req.Header.Set("Authorization", "Bearer <access-token>")
    req.Header.Set("X-Tenant-ID", "<tenant-id>")
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

const response = await fetch("https://api-<data-region>.central.sophos.com/common/v1/directory/user-groups/<groupId>/users", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <access-token>",
    "X-Tenant-ID": "<tenant-id>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "ids": [
    "3fa85f64-5717-4562-b3fc-2c963f66afa6"
  ]
}),
});
const data = await response.json();
console.log(data);

Responses

201 — Users added to the specified group.

Response fields

addedUsersarray of object
List of references to users added.
Reference to the user.
Show child attributesHide child attributes
idstring (uuid)required
User ID.
namestring
User's full name.

Errors

Status Meaning
404 Can't find group or at least one user in the request.
409 You can't modify groups synced from Active Directory. You also can't use this API to add users synced from Active Directory to a group.
500 Internal server error.

All error responses share the same shape — see the error response object.

Response examples

201

{
  "addedUsers": [
    {
      "id": "00000000-0000-0000-0000-000000000000",
      "name": "string"
    }
  ]
}