> For the complete documentation index, see [llms.txt](https://wemx.gitbook.io/wemx-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wemx.gitbook.io/wemx-api/api-reference/users.md).

# Users

This page covers all API endpoints for users

## Retrieve all users

<mark style="color:blue;">`GET`</mark> `https://wemx.app/api/v1/users`

Returns a list of all users on your application

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

<pre class="language-json"><code class="lang-json"><strong>{
</strong>    "status": true,
    "current_page": 1,
    "data": [
        {
            "id": 913,
            "username": "blanca.oberbrunner",
            "email": "demetris.schultz@example.net",
            "first_name": "Rosalinda",
            "last_name": "Howe",
            "status": "active",
            "balance": 0,
            "avatar": null,
            "is_subscribed": 0,
            "visibility": "online",
            "language": "en",
            "data": null,
            "email_verified_at": "2024-01-08T19:06:37.000000Z",
            "last_seen_at": "2024-01-08T20:06:38.000000Z",
            "last_login_at": "2024-01-08T20:06:38.000000Z",
            "created_at": "2024-01-08T19:06:38.000000Z",
            "updated_at": "2024-01-08T19:06:38.000000Z"
        },
    ],
    "first_page_url": "http://wemx.app/api/v1/users?page=1",
    "from": 1,
    "last_page": 99,
    "last_page_url": "http://wemx.app/api/v1/users?page=99",
    "links": [
        {
            "url": null,
            "label": "Previous",
            "active": false
        },
        {
            "url": "http://wemx.app/api/v1/users?page=1",
            "label": "1",
            "active": true
        },
        {
            "url": null,
            "label": "...",
            "active": false
        },
        {
            "url": "http://wemx.app/api/v1/users?page=98",
            "label": "98",
            "active": false
        },
        {
            "url": "http://wemx.app/api/v1/users?page=99",
            "label": "99",
            "active": false
        },
        {
            "url": "http://wemx.app/api/v1/users?page=2",
            "label": "Next",
            "active": false
        }
    ],
    "next_page_url": "http://wemx.app/api/v1/users?page=2",
    "path": "http://wemx.app/api/v1/users",
    "per_page": 15,
    "prev_page_url": null,
    "to": 15,
    "total": 1473
}
```
</code></pre>

{% endtab %}
{% endtabs %}

### Available Relationships (optional)

```
https://wemx.app/api/v1/users?include=address,orders,payments
```

#### Available relationships:

`balance_transactions`, `notifications`, `punishments`, `permissions`, `affiliate`, `suborder`, `orders`, `payments`, `devices`, `address`, `groups`, `emails`, `oauth`, `ips`

## Filters (optional)

```
https://wemx.app/api/v1/users?filter[is_online]=1&filter[is_subscribed]=1
```

#### Available Filters:

`first_name`, `last_name`, `username`, `email`, `is_subscribed`, `is_online`, `created_at`

## Sorting (optional)

```
https://wemx.app/api/v1/users?sort[balance]=asc
```

#### Available Sorting Parameters:

`first_name`, `last_name`, `username`, `email`, `balance`, `created_at`

#### Sorting operators

`asc`, `desc`, `random`

## Dates (optional)

```
https://wemx.app/api/v1/users?date=30days
```

<table><thead><tr><th width="392">Operator</th><th>Description</th></tr></thead><tbody><tr><td>today</td><td>Get users created today</td></tr><tr><td>yesterday</td><td>Get users created yesterday</td></tr><tr><td><code>3days</code>, <code>7days</code>, <code>14days</code>, <code>30days</code>, <code>90days</code></td><td>Get users created last x days</td></tr><tr><td>YYYY-MM-DD,YYY-MM-DD</td><td>Get users created between a range of dates</td></tr></tbody></table>

## Create a user

<mark style="color:green;">`POST`</mark> `https://wemx.app/api/v1/users`

Create a user on your application

#### Path Parameters

| Name                                          | Type    | Description                                                                |
| --------------------------------------------- | ------- | -------------------------------------------------------------------------- |
| first\_name<mark style="color:red;">\*</mark> | String  | First name of the user                                                     |
| last\_name<mark style="color:red;">\*</mark>  | String  | Last name of the user                                                      |
| username<mark style="color:red;">\*</mark>    | String  | Username of the user                                                       |
| email<mark style="color:red;">\*</mark>       | String  | Email of the user                                                          |
| password                                      | String  | Password of the user, leave empty to generate random password and email it |
| language                                      | Code    | Language code i.e "en"                                                     |
| address\[company\_name]                       | String  | Company name                                                               |
| address\[street]                              | String  | Street name of address                                                     |
| address\[street2]                             | String  | Second street name                                                         |
| address\[city]                                | String  | Name of city of the address                                                |
| address\[region]                              | String  | Name of the state / province / region                                      |
| address\[country]                             | Code    | Country code i.e "US", "DE", "NL"                                          |
| address\[zip\_code]                           | String  | Zip code of the address                                                    |
| welcome\_email                                | Boolean | Send an welcome email upon creation or not                                 |
| mark\_email\_verified                         | Boolean | Mark email as verified upon creation                                       |

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

```json
{
    "success": true,
    "data": {
        "username": "johndoe",
        "email": "johndoe@example.com",
        "language": "en",
        "first_name": "John",
        "last_name": "Doe",
        "status": "active",
        "last_login_at": "2024-01-09T18:06:58.000000Z",
        "updated_at": "2024-01-09T18:06:58.000000Z",
        "created_at": "2024-01-09T18:06:58.000000Z",
        "id": 2389,
        "address": {
            "id": 2256,
            "user_id": 2389,
            "company_name": null,
            "address": null,
            "address_2": null,
            "country": null,
            "city": null,
            "region": null,
            "zip_code": null,
            "created_at": "2024-01-09T18:06:58.000000Z",
            "updated_at": "2024-01-09T18:06:58.000000Z"
        }
    }
}
```

{% endtab %}
{% endtabs %}

## Get current authenticated user

<mark style="color:blue;">`GET`</mark> `https://wemx.app/api/v1/users/auth`

Returns the current user that is logged in

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

```json
{
   "status":true,
   "data":{
      "id": 523,
      "username": "johnsmith_",
      "email": "johnsmith@example.com",
      "first_name": "John",
      "last_name": "Smith",
      "language": "en",
      "avatar": "https://wemx.app/storage/avatars/8BKePJmpruAE4OV0.png",
      "status": "active",
      "is_subscribed": false,
      "is_email_verified": true,
      "last_seen_at": "2024-01-31T13:46:41.000000Z",
      "last_login_at": "2024-01-20T22:38:22.000000Z",
      "created_at": "2023-12-12T14:06:33.000000Z"
   }
}
```

{% endtab %}
{% endtabs %}

## Retrieve a user from id

<mark style="color:blue;">`GET`</mark> `https://wemx.app/api/v1/users/{user}`

Returns a user from id

#### Query Parameters

| Name                  | Type   | Description                                  |
| --------------------- | ------ | -------------------------------------------- |
| balance\_transactions |        | Returns user with their balance transactions |
| notifications         | String | User with their notifications                |
| payments              | String | Users with their payments                    |
| orders                | String | Users with their orders                      |
| suborders             | String | Users with their suborders                   |
| affiliate             | String | User with their affiliate info               |
| permissions           | String | User with their permissions                  |
| punishments           | String | User with their punishments                  |
| address               | String | Users with their address                     |
| devices               | String | Users with their devices                     |
| groups                | String | Users with their groups                      |
| emails                | String | Users with their emails                      |
| oauth                 | String | Users with their oauth services              |
| ips                   | String | Users with their IP Addresses                |

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

```json
{
    "status": true,
    "data": {
        "id": 913,
        "username": "blanca.oberbrunner",
        "email": "demetris.schultz@example.net",
        "first_name": "Rosalinda",
        "last_name": "Howe",
        "status": "active",
        "balance": 0,
        "avatar": null,
        "is_subscribed": 0,
        "visibility": "online",
        "language": "en",
        "data": null,
        "email_verified_at": "2024-01-08T19:06:37.000000Z",
        "last_seen_at": "2024-01-08T20:06:38.000000Z",
        "last_login_at": "2024-01-08T20:06:38.000000Z",
        "created_at": "2024-01-08T19:06:38.000000Z",
        "updated_at": "2024-01-08T19:06:38.000000Z"
    }
}
```

{% endtab %}
{% endtabs %}

## Update user details

<mark style="color:orange;">`PUT`</mark> `https://wemx.app/api/v1/users/{user}`

Update a users information, only values that are passed in the body are updated, the remaining values remain as default if they are not specified.

#### Request Body

| Name        | Type   | Description             |
| ----------- | ------ | ----------------------- |
| first\_name | String | First name of the user  |
| last\_name  | String | Last name of the user   |
| username    | String | Username of the user    |
| password    | String | Password of the user    |
| language    | Code   | String of the user "en" |

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

```json
{
    "success": true,
    "data": {
        "id": 2389,
        "username": "johndoe",
        "email": "johndoe@example.com",
        "first_name": "John",
        "last_name": "Doe",
        "status": "active",
        "balance": 0,
        "avatar": null,
        "is_subscribed": 0,
        "visibility": "online",
        "language": "en",
        "data": null,
        "email_verified_at": null,
        "last_seen_at": "2024-01-09T19:06:58.000000Z",
        "last_login_at": "2024-01-09T18:06:58.000000Z",
        "created_at": "2024-01-09T18:06:58.000000Z",
        "updated_at": "2024-01-09T18:06:58.000000Z"
    }
}
```

{% endtab %}
{% endtabs %}

## Delete a user

<mark style="color:red;">`DELETE`</mark> `https://wemx.app/api/v1/users/{user}`

Delete a user permanently from your application. The user cannot have any active, or suspended orders and must not have any punishments on record.

#### Request Body

| Name  | Type    | Description                                                                                      |
| ----- | ------- | ------------------------------------------------------------------------------------------------ |
| force | Boolean | Delete user forcefully, ignores whether the user has active orders or has punishments on record. |

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

```json
{
    "success": true,
    "message": "User deleted successfully"
}
```

{% endtab %}
{% endtabs %}

## Retrieve orders for a user

<mark style="color:blue;">`GET`</mark> `https://wemx.app/api/v1/users/{user}/orders`

Returns all orders the user owns

## Retrieve payments for a user

<mark style="color:blue;">`GET`</mark> `https://wemx.app/api/v1/users/{user}/payments`

Returns all payments the user has made

## Update user balance

<mark style="color:orange;">`PUT`</mark> `https://wemx.app/api/v1/users/{user}/update-balance`

Update a users balance

#### Path Parameters

| Name                                     | Type   | Description                    |
| ---------------------------------------- | ------ | ------------------------------ |
| type<mark style="color:red;">\*</mark>   | Enum   | add, remove or set             |
| amount<mark style="color:red;">\*</mark> | Number | The amount you wish to update  |
| description                              | String | Description of the transaction |

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

```json
{
    "success": true,
    "message": "Balance updated successfully"
}
```

{% endtab %}
{% endtabs %}

## Send a user an email

<mark style="color:green;">`POST`</mark> `https://wemx.app/api/v1/users/{user}/send-email`

Email the user through your application

#### Path Parameters

| Name                                      | Type   | Description                             |
| ----------------------------------------- | ------ | --------------------------------------- |
| subject<mark style="color:red;">\*</mark> | String | Subject of the email                    |
| content<mark style="color:red;">\*</mark> | String | Content of the email, HTML is supported |

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

```json
{
    "success": true,
    "message": "Email sent successfully"
}
```

{% endtab %}
{% endtabs %}

## Notify a user

<mark style="color:green;">`POST`</mark> `https://wemx.app/api/v1/users/{user}/send-notification`

Send a notification to the user

#### Path Parameters

| Name                                      | Type   | Description                                          |
| ----------------------------------------- | ------ | ---------------------------------------------------- |
| type<mark style="color:red;">\*</mark>    | Enum   | success, warning, danger                             |
| icon<mark style="color:red;">\*</mark>    | Icon   | SVG or font icon from BoxIcons                       |
| message<mark style="color:red;">\*</mark> | String | Message on the notification                          |
| url                                       | URL    | URL the notification should redirect to when clicked |

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

```json
{
    "success": true,
    "message": "Notification sent successfully"
}
```

{% endtab %}
{% endtabs %}
