Loading...
 
Skip to main content

History: Api Groups Doc

Source of version: 6 (current)

Copy to clipboard
{DIV(class="content-section d-none" id="get-groups")}
!!! Retrieve groups.

Retrieve a list of user groups with pagination and optional filtering.

{TABS(name="doc-get-groups" tabs="Request URL| cURL | PHP | JavaScript | Response" toggle="y" inside_pretty="n")}

{DIV()}
{CODE(caption="Request URL - groups" colors="http" theme="default")}
https://example.com/api/groups
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="cURL - groups" colors="http" theme="default")}
curl --request GET \
     --url "https://example.com/api/groups" \
     --data-urlencode "offset=-1" \
     --data-urlencode "maxRecords=3" \
     --header "accept: application/json" \
     --header "Authorization: Bearer <API_TOKEN>"
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="PHP - groups" colors="php" theme="default")}
<?php

$base_url = 'https://example.com/api/groups';

$params = [
    'offset' => -1,
    'maxRecords' => 3
];

$url = $base_url . '?' . http_build_query($params);

$headers = [
    'Accept: application/json',
    'Authorization: Bearer <API_TOKEN>'
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($http_code === 200) {
        $data = json_decode($response, true);
        print_r($data);
    } else {
        echo 'Error: HTTP status code ' . $http_code;
    }
}

curl_close($ch);

?>
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Javascript - groups" colors="javascript" theme="default")}
const params = new URLSearchParams({
  offset: '-1',
  maxRecords: '3'
});

fetch('https://example.com/api/groups?' + params.toString(), {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Authorization': 'Bearer <API_TOKEN>'
    }
  })
  .then(res => {
    if (!res.ok) throw new Error("HTTP " + res.status);
    return res.json();
  })
  .then(data => {
    console.log(data);
  })
  .catch(err => {
    console.log('Fetch error: ' + err.message);
  });

{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Response - groups" colors="json" theme="default")}
{
  "data": [
    {
      "id": 1,
      "groupName": "Anonymous",
      "groupDesc": "Public users not logged",
      "groupHome": null,
      "usersTrackerId": null,
      "groupTrackerId": null,
      "usersFieldId": null,
      "groupFieldId": null,
      "registrationChoice": null,
      "registrationUsersFieldIds": null,
      "userChoice": null,
      "groupDefCat": 0,
      "groupTheme": "",
      "groupColor": "",
      "isExternal": "n",
      "expireAfter": 0,
      "emailPattern": "",
      "anniversary": "",
      "prorateInterval": "",
      "isRole": "n",
      "isTplGroup": "n",
      "perms": [
        "tiki_p_admin_tikitests",
        "tiki_p_download_files",
        "tiki_p_edit_tikitests",
        "tiki_p_export_pdf",
        "tiki_p_play_tikitests",
        "tiki_p_print",
        "tiki_p_search",
        "tiki_p_view"
      ],
      "permCount": 8,
      "included": [],
      "included_direct": []
    },
    {
      "id": 2,
      "groupName": "Registered",
      "groupDesc": "Users logged into the system",
      "groupHome": null,
      "usersTrackerId": null,
      "groupTrackerId": null,
      "usersFieldId": null,
      "groupFieldId": null,
      "registrationChoice": null,
      "registrationUsersFieldIds": null,
      "userChoice": null,
      "groupDefCat": 0,
      "groupTheme": "",
      "groupColor": "",
      "isExternal": "n",
      "expireAfter": 0,
      "emailPattern": "",
      "anniversary": "",
      "prorateInterval": "",
      "isRole": "n",
      "isTplGroup": "n",
      "perms": [
        "tiki_p_admin_tikitests",
        "tiki_p_edit_tikitests",
        "tiki_p_export_pdf",
        "tiki_p_play_tikitests",
        "tiki_p_print",
        "tiki_p_view_category"
      ],
      "permCount": 6,
      "included": [
        "Anonymous"
      ],
      "included_direct": [
        "Anonymous"
      ]
    },
    {
      "id": 3,
      "groupName": "Admins",
      "groupDesc": "Administrator and accounts managers.",
      "groupHome": null,
      "usersTrackerId": null,
      "groupTrackerId": null,
      "usersFieldId": null,
      "groupFieldId": null,
      "registrationChoice": null,
      "registrationUsersFieldIds": null,
      "userChoice": null,
      "groupDefCat": 0,
      "groupTheme": "",
      "groupColor": "",
      "isExternal": "n",
      "expireAfter": 0,
      "emailPattern": "",
      "anniversary": "",
      "prorateInterval": "",
      "isRole": "n",
      "isTplGroup": "n",
      "perms": [
        "tiki_p_admin",
        "tiki_p_admin_tikitests",
        "tiki_p_edit_tikitests",
        "tiki_p_export_pdf",
        "tiki_p_play_tikitests",
        "tiki_p_print",
        "tiki_p_remove_share",
        "tiki_p_view_category"
      ],
      "permCount": 8,
      "included": [],
      "included_direct": []
    }
  ],
  "count": 5
}
{CODE}
{DIV}

{TABS}


!!!! Parameters

* __offset__ ''integer optional'' : Offset to start from
* __maxRecords__ ''integer optional'' : Maximum number of records to return
* __find__ ''string optional'' : Search string to filter groups
* __initial__ ''string optional'' : Initial string to match group names

{DIV}

{DIV(class="content-section d-none" id="create-groups")}
!!! Create a new user group

Create a new user group with optional configuration parameters.

{TABS(name="doc-create-groups" tabs="Request URL| cURL | PHP | JavaScript | Response" toggle="y" inside_pretty="n")}

{DIV()}
{CODE(caption="Request URL - groups" colors="http" theme="default")}
https://example.com/api/groups
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="cURL - groups" colors="http" theme="default")}
curl --request POST \
     --url "https://example.com/api/groups" \
     --header "accept: application/json" \
     --header "Authorization: Bearer <API_TOKEN>" \
     --header "Content-Type: application/x-www-form-urlencoded" \
     --data-urlencode "name=Test Group" \
     --data-urlencode "userChoice=y" \
     --data-urlencode "desc=Test Group Description"
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="PHP - groups" colors="php" theme="default")}
<?php

$url = 'https://example.com/api/groups';
$headers = [
    'Accept: application/json',
    'Authorization: Bearer <API_TOKEN>',
    'Content-Type: application/x-www-form-urlencoded'
];

$postFields = http_build_query([
    'name' => 'Test Group',
    'userChoice' => 'y',
    'desc' => 'Test Group Description'
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($http_code === 200) {
        $data = json_decode($response, true);
        print_r($data);
    } else {
        echo 'Error: HTTP status code ' . $http_code;
    }
}

curl_close($ch);


?>
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Javascript - groups" colors="javascript" theme="default")}
const params = new URLSearchParams({
  name: 'Test Group',
  userChoice: 'y',
  desc: 'Test Group Description'
});

fetch('https://example.com/api/groups', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Authorization': 'Bearer <API_TOKEN>',
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: params.toString()
  })
  .then(res => {
    if (!res.ok) throw new Error("HTTP " + res.status);
    return res.json();
  })
  .then(data => {
    console.log(data);
  })
  .catch(err => {
    console.log('Fetch error: ' + err.message);
  });

{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Response - groups" colors="json" theme="default")}
{
  "feedback": {
    "action": [
      {
        "type": "feedback",
        "icon": "success",
        "title": "Success",
        "mes": [
          "Group Test Group (ID 6) successfully created"
        ]
      }
    ]
  }
}
{CODE}
{DIV}

{TABS}


!!!! Request body

* __name__ ''string'' ~~#fe0000:*~~: The name of the group
* __desc__ ''string optional'' : The description of the group
* __home__ ''string optional'' : The home page of the group
* __userstracker__ ''integer optional'' : The tracker ID for the users. Choose a user tracker to provide fields for a new user to complete upon registration.
* __usersfield__ ''integer optional'' : The field ID for the users. Select the user selector field from the above tracker (~~#9011ff:__userstracker__~~) to link a tracker item to the user upon registration.
* __groupstracker__ ''integer optional'' : The tracker ID for the group.
* __groupfield__ ''integer optional'' : The field ID for the group. Select the group selector field from the above tracker (~~#9011ff:__groupstracker__~~) to link a tracker item to the group upon registration.
* __registrationUsersFieldIds__ ''string optional'' : If either a group information tracker or user registration tracker has been selected above, enter colon-separated field ID numbers for the tracker fields in the above tracker to include on the registration form for a new user to complete.
* __userChoice__ ''string optional'' : User can assign himself or herself to the group. Possible values are:
** ~~#9011ff:__y__~~ : Yes. User can assign himself or herself to the group
** ~~#9011ff:__n__~~ : No. User cannot assign himself or herself to the group.
* __defcat__ ''integer optional'' : The Default category assigned to uncategorized objects edited by a user with this default group.
* __theme__ ''string optional'' : The theme of the group. Possible values are:
** ~~#9011ff:__default__~~ : Default theme.
** ~~#9011ff:__custom_url__~~ : Custom theme by specifying URL
** ~~#9011ff:__amelia__~~ : Amelia theme.
** ~~#9011ff:__cerulean__~~ : Cerulean theme.
** ~~#9011ff:__cosmo__~~ : Cosmo theme.
** ~~#9011ff:__cyborg__~~ : Cyborg theme.
** ~~#9011ff:__darkly__~~ : Darkly theme.
** ~~#9011ff:__flatly__~~ : Flatly theme.
** etc. (see https://bootswatch.com/ for more themes)
* __expireAfter__ ''integer optional'' : Number of days after which all users will be unassigned from the group.
* __emailPattern__ ''string optional'' : Users are automatically assigned at registration in the group if their emails match the pattern.
** Example: /@(tw.org$)|(tw.com$)/
* __anniversary__ ''string optional'' : Use ~~#9011ff:__MMDD__~~ to specify an annual date as of which all users will be unassigned from the group, or ~~#9011ff:__DD__~~ to specify a monthly date.
* __prorateInterval__ ''string optional'' : The Payment for membership extension is prorated at a minimum interval. Possible values are:
** ~~#9011ff:__day__~~ : Daily prorate interval.
** ~~#9011ff:__month__~~ : Monthly prorate interval.
** ~~#9011ff:__year__~~ : Yearly prorate interval.
* __color__ ''string optional'' : The Default color to use when plotting values for this group in charts. Use HEX notation, e.g. ~~#9011ff:__#FF0000__~~ for red color.
* __isRole__ ''string optional'' : The group is a role. Possible values are:
** ~~#9011ff:__y__~~ : Yes. The group is a role.
** ~~#9011ff:__n__~~ : No. The group is not a role.
** Note: If the group is a role, it will be used to assign permissions to users. Role groups can't have users.
* __isTplGroup__ ''string optional'' : The group is a template group. Possible values are:
** ~~#9011ff:__y__~~ : Yes. The group is a template group.
** ~~#9011ff:__n__~~ : No. The group is not a template group.
* __include_groups[]__ ''array optional'' : The groups to include in this group. Consider it as a parent group, the group from which this group inherits permissions.

{DIV}

{DIV(class="content-section d-none" id="update-groups")}
!!! Update an existing user group

Update an existing user group’s configuration, description, or name.

{TABS(name="doc-update-groups" tabs="Request URL| cURL | PHP | JavaScript | Response" toggle="y" inside_pretty="n")}

{DIV()}
{CODE(caption="Request URL - groups" colors="http" theme="default")}
https://example.com/api/groups/{olgroup}
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="cURL - groups" colors="http" theme="default")}
curl --request POST \
     --url "https://example.com/api/groups/Test%20Group" \
     --header "accept: application/json" \
     --header "Authorization: Bearer <API_TOKEN>" \
     --header "Content-Type: application/x-www-form-urlencoded" \
     --data-urlencode "isRole=y" \
     --data-urlencode "name=Test Group Updated" \
     --data-urlencode "userChoice=n" \
     --data-urlencode "desc=Test Group Description Updated"
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="PHP - groups" colors="php" theme="default")}
<?php

$url = 'https://example.com/api/groups/Test%20Group';

$headers = [
    'Accept: application/json',
    'Authorization: Bearer <API_TOKEN>',
    'Content-Type: application/x-www-form-urlencoded'
];

$postFields = http_build_query([
    'isRole' => 'y',
    'name' => 'Test Group Updated',
    'userChoice' => 'n',
    'desc' => 'Test Group Description Updated'
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($http_code === 200) {
        $data = json_decode($response, true);
        print_r($data);
    } else {
        echo 'Error: HTTP status code ' . $http_code;
    }
}

curl_close($ch);

?>
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Javascript - groups" colors="javascript" theme="default")}
const params = new URLSearchParams({
  isRole: 'y',
  name: 'Test Group Updated',
  userChoice: 'n',
  desc: 'Test Group Description Updated'
});

fetch('https://example.com/api/groups/Test%20Group', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Authorization': 'Bearer <API_TOKEN>',
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: params.toString()
  })
  .then(res => {
    if (!res.ok) throw new Error("HTTP " + res.status);
    return res.json();
  })
  .then(data => {
    console.log(data);
  })
  .catch(err => {
    console.log('Fetch error: ' + err.message);
  });

{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Response - groups" colors="json" theme="default")}
{
  "feedback": {
    "action": [
      {
        "type": "feedback",
        "icon": "success",
        "title": "Success",
        "mes": [
          "Group Test Group Updated successfully modified"
        ]
      }
    ]
  }
}
{CODE}
{DIV}

{TABS}

!!!! Parameters

* __olgroup__ ''string'' ~~#fe0000:*~~: The original name of the group to update

!!!! Request body

* __name__ ''string optional'' : The name of the group
* __desc__ ''string optional'' : The description of the group
* __home__ ''string optional'' : The home page of the group
* __userstracker__ ''integer optional'' : The tracker ID for the users. Choose a user tracker to provide fields for a new user to complete upon registration.
* __usersfield__ ''integer optional'' : The field ID for the users. Select the user selector field from the above tracker (~~#9011ff:__userstracker__~~) to link a tracker item to the user upon registration.
* __groupstracker__ ''integer optional'' : The tracker ID for the group.
* __groupfield__ ''integer optional'' : The field ID for the group. Select the group selector field from the above tracker (~~#9011ff:__groupstracker__~~) to link a tracker item to the group upon registration.
* __registrationUsersFieldIds__ ''string optional'' : If either a group information tracker or user registration tracker has been selected above, enter colon-separated field ID numbers for the tracker fields in the above tracker to include on the registration form for a new user to complete.
* __userChoice__ ''string optional'' : User can assign himself or herself to the group. Possible values are:
** ~~#9011ff:__y__~~ : Yes. User can assign himself or herself to the group
** ~~#9011ff:__n__~~ : No. User cannot assign himself or herself to the group.
* __defcat__ ''integer optional'' : The Default category assigned to uncategorized objects edited by a user with this default group.
* __theme__ ''string optional'' : The theme of the group. Possible values are:
** ~~#9011ff:__default__~~ : Default theme.
** ~~#9011ff:__custom_url__~~ : Custom theme by specifying URL
** ~~#9011ff:__amelia__~~ : Amelia theme.
** ~~#9011ff:__cerulean__~~ : Cerulean theme.
** ~~#9011ff:__cosmo__~~ : Cosmo theme.
** ~~#9011ff:__cyborg__~~ : Cyborg theme.
** ~~#9011ff:__darkly__~~ : Darkly theme.
** ~~#9011ff:__flatly__~~ : Flatly theme.
** etc. (see https://bootswatch.com/ for more themes)
* __expireAfter__ ''integer optional'' : Number of days after which all users will be unassigned from the group.
* __emailPattern__ ''string optional'' : Users are automatically assigned at registration in the group if their emails match the pattern.
** Example: /@(tw.org$)|(tw.com$)/
* __anniversary__ ''string optional'' : Use ~~#9011ff:__MMDD__~~ to specify an annual date as of which all users will be unassigned from the group, or ~~#9011ff:__DD__~~ to specify a monthly date.
* __prorateInterval__ ''string optional'' : The Payment for membership extension is prorated at a minimum interval. Possible values are:
** ~~#9011ff:__day__~~ : Daily prorate interval.
** ~~#9011ff:__month__~~ : Monthly prorate interval.
** ~~#9011ff:__year__~~ : Yearly prorate interval.
* __color__ ''string optional'' : The Default color to use when plotting values for this group in charts. Use HEX notation, e.g. ~~#9011ff:__#FF0000__~~ for red color.
* __isRole__ ''string optional'' : The group is a role. Possible values are:
** ~~#9011ff:__y__~~ : Yes. The group is a role.
** ~~#9011ff:__n__~~ : No. The group is not a role.
** Note: If the group is a role, it will be used to assign permissions to users. Role groups can't have users.
* __isTplGroup__ ''string optional'' : The group is a template group. Possible values are:
** ~~#9011ff:__y__~~ : Yes. The group is a template group.
** ~~#9011ff:__n__~~ : No. The group is not a template group.
* __include_groups[]__ ''array optional'' : The groups to include in this group. Consider it as a parent group, the group from which this group inherits permissions.

{DIV}

{DIV(class="content-section d-none" id="add-user-groups")}
!!! Add one or more users to a specified group.

Add one or more users to a specified group.

{TABS(name="doc-add-user-groups" tabs="Request URL| cURL | PHP | JavaScript | Response" toggle="y" inside_pretty="n")}

{DIV()}
{CODE(caption="Request URL - groups" colors="http" theme="default")}
https://example.com/api/groups/add_users
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="cURL - groups" colors="http" theme="default")}
curl --request POST \
     --url "https://example.com/api/groups/add_users" \
     --header "accept: application/json" \
     --header "Authorization: Bearer <API_TOKEN>" \
     --header "Content-Type: application/x-www-form-urlencoded" \
     --data-urlencode "group=Test Group Updated" \
     --data-urlencode "items[]=test-user" \
     --data-urlencode "items[]=test-user-2"
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="PHP - groups" colors="php" theme="default")}
<?php

$url = 'https://example.com/api/groups/add_users';

$headers = [
    'Accept: application/json',
    'Authorization: Bearer <API_TOKEN>',
    'Content-Type: application/x-www-form-urlencoded'
];

$postFields = http_build_query([
    'group' => 'Test Group Updated',
    'items' => ['test-user', 'test-user-2']
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($status === 200) {
        echo json_encode(json_decode($response, true), JSON_PRETTY_PRINT);
    } else {
        echo "Error: HTTP $status";
    }
}

curl_close($ch);

?>
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Javascript - groups" colors="javascript" theme="default")}
const params = new URLSearchParams({
  group: 'Test Group Updated',
  'items[]': 'test-user',
  'items[]': 'test-user-2'
});

fetch('https://example.com/api/groups/add_users', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Authorization': 'Bearer <API_TOKEN>',
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: params.toString()
  })
  .then(res => {
    if (!res.ok) throw new Error("HTTP " + res.status);
    return res.json();
  })
  .then(data => {
    console.log(data);
  })
  .catch(err => {
    console.error('Fetch error: ' + err.message);
  });

{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Response - groups" colors="json" theme="default")}
{
  "feedback": {
    "action": [
      {
        "type": "feedback",
        "icon": "success",
        "title": "Success",
        "mes": [
          "The following user was added to group Test Group Updated:"
        ],
        "items": [
          "test-user",
          "test-user-2"
        ]
      }
    ]
  }
}
{CODE}
{DIV}

{TABS}

!!!! Request body

* __group__ ''string'' ~~#fe0000:*~~: The name of the group to which users will be added
* __items[]__ ''array'' ~~#fe0000:*~~: The usernames of the users to add

{DIV}

{DIV(class="content-section d-none" id="ban-user-groups")}
!!! Ban one or more users from a specified group.

Ban one or more users from a specified group.

{TABS(name="doc-ban-user-groups" tabs="Request URL| cURL | PHP | JavaScript | Response" toggle="y" inside_pretty="n")}

{DIV()}
{CODE(caption="Request URL - groups" colors="http" theme="default")}
https://example.com/api/groups/ban_users
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="cURL - groups" colors="http" theme="default")}
curl --request POST \
     --url "https://example.com/api/groups/ban_users" \
     --header "accept: application/json" \
     --header "Authorization: Bearer <API_TOKEN>" \
     --header "Content-Type: application/x-www-form-urlencoded" \
     --data-urlencode "group=Test Group Updated" \
     --data-urlencode "items[]=test-user" \
     --data-urlencode "items[]=test-user-2"
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="PHP - groups" colors="php" theme="default")}
<?php

$url = 'https://example.com/api/groups/ban_users';

$headers = [
    'Accept: application/json',
    'Authorization: Bearer <API_TOKEN>',
    'Content-Type: application/x-www-form-urlencoded'
];

$postFields = http_build_query([
    'group' => 'Test Group Updated',
    'items' => ['test-user', 'test-user-2']
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($status === 200) {
        echo json_encode(json_decode($response, true), JSON_PRETTY_PRINT);
    } else {
        echo "Error: HTTP $status";
    }
}

curl_close($ch);

?>
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Javascript - groups" colors="javascript" theme="default")}
const params = new URLSearchParams({
  group: 'Test Group Updated',
  'items[]': 'test-user',
  'items[]': 'test-user-2'
});

fetch('https://example.com/api/groups/ban_users', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Authorization': 'Bearer <API_TOKEN>',
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: params.toString()
  })
  .then(res => {
    if (!res.ok) throw new Error("HTTP " + res.status);
    return res.json();
  })
  .then(data => {
    console.log(data);
  })
  .catch(err => {
    console.error('Fetch error: ' + err.message);
  });

{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Response - groups" colors="json" theme="default")}
{
  "feedback": {
    "action": [
      {
        "type": "feedback",
        "icon": "success",
        "title": "Success",
        "mes": [
          "The following user was banned from group Test Group Updated:"
        ],
        "items": [
          "test-user",
          "test-user-2"
        ]
      }
    ]
  }
}
{CODE}
{DIV}

{TABS}

!!!! Request body

* __group__ ''string'' ~~#fe0000:*~~: The name of the group from which users will be banned
* __items[]__ ''array'' ~~#fe0000:*~~: The usernames of the users to ban

{DIV}


{DIV(class="content-section d-none" id="delete-groups")}
!!! Delete one or more groups from the system.

Delete one or more groups from the system.

{TABS(name="doc-delete-groups" tabs="Request URL| cURL | PHP | JavaScript | Response" toggle="y" inside_pretty="n")}

{DIV()}
{CODE(caption="Request URL - groups" colors="http" theme="default")}
https://example.com/api/groups/delete
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="cURL - groups" colors="http" theme="default")}
curl --request POST \
     --url "https://example.com/api/groups/delete" \
     --header "accept: application/json" \
     --header "Authorization: Bearer <API_TOKEN>" \
     --header "Content-Type: application/x-www-form-urlencoded" \
     --data-urlencode "items[]=Test Group Updated" \
     --data-urlencode "items[]=Translators Group"
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="PHP - groups" colors="php" theme="default")}
<?php

$url = 'https://example.com/api/groups/delete';

$data = http_build_query([
    'items' => ['Test Group Updated', 'Translators Group']
]);

$headers = [
    'Accept: application/json',
    'Authorization: Bearer <API_TOKEN>',
    'Content-Type: application/x-www-form-urlencoded'
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($http_code === 200) {
    $data = json_decode($response, true);
    print_r($data);
} else {
    echo 'Error: HTTP status code ' . $http_code;
}

curl_close($ch);

?>
{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Javascript - groups" colors="javascript" theme="default")}
const formData = new URLSearchParams();
formData.append('items[]', 'Test Group Updated');
formData.append('items[]', 'Translators Group');

fetch('https://example.com/api/groups/delete', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Authorization': 'Bearer <API_TOKEN>',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: formData.toString()
})
.then(res => {
  if (!res.ok) throw new Error("HTTP " + res.status);
  return res.json();
})
.then(data => {
  console.log(data);
})
.catch(err => {
  console.log('Fetch error: ' + err.message);
});

{CODE}
{DIV}

/////
{DIV()}
{CODE(caption="Response - groups" colors="json" theme="default")}
{
  "feedback": {
    "action": [
      {
        "type": "feedback",
        "icon": "success",
        "title": "Success",
        "mes": [
          "The following group has been deleted:"
        ],
        "items": [
          "Test Group Updated",
          "Translators Group"
        ]
      }
    ]
  }
}

{CODE}
{DIV}

{TABS}

!!!! Request body

* __items[]__ ''array'' ~~#fe0000:*~~: The list of group names to delete

{DIV}


Show PHP error messages