# User Roles

## Get User Roles

<mark style="color:blue;">`GET`</mark> `‎https://<domain>/<api prefix>/<version>/user/get/roles/`

This API endpoint will give you the user roles details.

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access-token |

{% tabs %}
{% tab title="200 " %}

```markup
HTTP/1.1 200 OK
Content-Type: application/json

Body:
{
    "status_code": 200,
    "errors": {},
    "data": {
        "UserRoles": [
            {
                "id": <role-id>,
                "name": "<role-name>"
            },
            ...
        ],
        "AllGroups": [
            {
                "<role-id>": "<role-name>"
            },
            ...
        ],
        "g_placed": <geneology_placed_or_not>
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://<domain>/<api prefix>/<version>/user/get/roles/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access-token>',
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://<domain>/<api prefix>/<version>/user/get/roles/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "apikey: <apikey>",
    "Authorization: Bearer <access-token>",
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

## Upgrade User Role

<mark style="color:green;">`POST`</mark> `‎https://<domain>/<api prefix>/<version>/upgrade/user-role/`

This API endpooint will upgrade a user role from customer to preferred customer or to member.           &#x20;

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

#### Request Body

| Name                                          | Type   | Description                                                                                                                                                                                                                                                                               |
| --------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| unique\_id<mark style="color:red;">\*</mark>  | string | User unique id.                                                                                                                                                                                                                                                                           |
| upgrade\_to<mark style="color:red;">\*</mark> | string | <p>Upgrade options, possible values are:<br><strong>Member</strong> - Upgrade user role from customer to member.<br><strong>Preferred Customer</strong> - Upgrade user role from customer to preferred customer.</p>                                                                      |
| api\_place\_genealogy                         | string | <p>api\_place\_genealogy is required when upgrading the role from customer to preferred customer.<br>Possible values are:<br><strong>True</strong> - Place the user in genealogy when upgrading to preferred customer<br><strong>False</strong> - Do not place the user in genealogy.</p> |

{% tabs %}
{% tab title="200 " %}

```markup
HTTP/1.1 200 OK
Content-Type: application/json

Body:
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://<domain>/<api prefix>/<version>/upgrade/user-role/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access-token>' 
  },
  formData: {
    'unique_id': '<user_unique_id>',
    'upgrade_to': '<upgrade_option>',
    'api_place_genealogy': '<True_or_False>'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/upgrade/user-role/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('unique_id' => '<user_unique_id>','upgrade_to' => '<upgrade_option>','api_place_genealogy' => '<True_or_False>'),
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access-token>'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

| Status Code | Error Type       | Field                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ----------- | ---------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 400         | Validation Error | unique\_id            | <p>This field is required and its may not be blank.</p><p>User not exist or invalid unique id.</p><p>Ensure this field has no more than 255 characters.</p>                                                                                                                                                                                                                                                                           |
| 400         | Validation Error | upgrade\_to           | <p>This field is required and its may not be blank.</p><p>Invalid upgrade option, Choose a valid one.</p>                                                                                                                                                                                                                                                                                                                             |
| 400         | Validation Erorr | api\_place\_genealogy | <p>This field is required and its may not be blank.</p><p>Choose a valid option.</p>                                                                                                                                                                                                                                                                                                                                                  |
| 403         | Request Failed   |                       | <p>User role is already upgraded.</p><p>User already have a member role.</p><p>User already have a preferred customer role.</p><p>Free user place genealogy disabled, can't upgrade user role.</p><p>Free package for user role upgrade is not created.</p><p>User role upgrade option not found.</p><p>Created free package is not a customer privilaged package.</p><p>Created free package is not a member privilaged package.</p> |

## Downgrade User Role

<mark style="color:green;">`POST`</mark> `‎https://<domain>/<api prefix>/<version>/downgrade/user-role/`

This API endpoint will downgrade a user role from member to preferred customer or to customer.

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

#### Request Body

| Name                                               | Type   | Description                                                                                                                                                                                                                |
| -------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| unique\_id<mark style="color:red;">\*</mark>       | string | user unique id                                                                                                                                                                                                             |
| downgrade\_to<mark style="color:red;">\*</mark>    | string | <p>Downgrade options, possible values are: <br><strong>Customer</strong> - Downgrade user role from member to customer.<br><strong>Preferred Customer</strong> - Downgrade user role from member to preferred customer</p> |
| api\_block\_user<mark style="color:red;">\*</mark> | string | <p>Block the user with role downgrade, Possible values are:<br><strong>True</strong> - Block user account.<br><strong>False</strong> - Do not block.</p>                                                                   |

{% tabs %}
{% tab title="200 " %}

```markup
HTTP/1.1 200 OK
Content-Type: application/json

Body:
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

**Node**

```php
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://<domain>/<api prefix>/<version>/downgrade/user-role/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access-token>'
  },
  formData: {
    'unique_id': '<user_unique_id>',
    'downgrade_to': '<downgrade_option>'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/downgrade/user-role/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('unique_id' => '<user_unique_id>','downgrade_to' => '<downgrade_option>'),
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access-token>'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

**Error Responses**

| Status Code | Error Type       | Field            | Description                                                                                                                                                        |
| ----------- | ---------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 400         | Validation Error | unique\_id       | <p>This field is required and its may not be blank.</p><p>User not exist or invalid unique id.</p><p>Ensure this field has no more than 255 characters.</p>        |
| 400         | Validation Error | downgrade\_to    | <p>This field is required and its may not be blank.</p><p>Invalid downgrade option, Choose a valid one.</p>                                                        |
| 400         | Validation Erorr | api\_block\_user | Choose a valid option.                                                                                                                                             |
| 403         | Request Failed   |                  | <p>User already have a downgraded role.</p><p>User already have a customer role.</p><p>User already have a preferred customer role.</p><p>Somthing went wrong.</p> |


---

# Agent Instructions: 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:

```
GET https://api.epixelsoftware.help/user-roles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
