Add to groups¶
POST/
Common API · Directory Management
Add a user to multiple groups.
Parameters¶
| Name | In | Type | Required | Description |
|---|---|---|---|---|
X-Tenant-ID | header | string (uuid) | Yes | Tenant ID. |
userId | path | string (uuid) | Yes | User ID. |
Request body¶
Content type: application/json
Request body fields
idsarray of string (uuid)requiredList of group IDs.
Must contain at most 50 items. Items must be unique.
Must contain at most 50 items. Items must be unique.
Request samples¶
curl -X POST "https://api-<data-region>.central.sophos.com/common/v1/directory/users/<userId>/groups" -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/users/<userId>/groups",
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/users/<userId>/groups" -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/users/<userId>/groups", 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/users/<userId>/groups", {
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 — User added to the specified groups.¶
Response fields
addedToGroupsarray of objectList of references to groups to which the user was added.
Group reference.
Show child attributesHide child attributes
idstring (uuid)requiredGroup ID.
namestringGroup name.
displayNamestringDisplay name.
Errors¶
| Status | Meaning |
|---|---|
404 | Can't find user or at least one group in the request. |
409 | You can't modify users synced from Active Directory. You also can't use this API to add users to groups synced from Active Directory. |
500 | Internal server error. |
All error responses share the same shape — see the error response object.