# Users

## Listing des utilisateurs

<mark style="color:green;">GET</mark> `https://api.cards-microlearning.com/v1/users`

Récupération d'une liste d'utilisateurs.&#x20;

Cette liste peut être filtrée et est paginée.

**Entête (Headers)**

| Nom           | Valeur                                   |
| ------------- | ---------------------------------------- |
| Content-Type  | `application/json`                       |
| Authorization | `Bearer <token API>`                     |
| X-Tenant      | `<Identifiant de votre espace (Tenant)>` |

**Paramètre de l'url**

<table><thead><tr><th width="155">Nom</th><th width="137">Type</th><th width="289">Description</th><th width="166">Valeurs</th></tr></thead><tbody><tr><td><code>paginate</code></td><td>Nombre entier</td><td>Nombre d'élément dans la liste par page</td><td>Défaut : 100<br>Max : 500</td></tr><tr><td><code>filters</code></td><td>Tableau Json</td><td><p>Permet de filtrer sur un rôle, identifiant ou nom du groupe.<br>Chaque entrée dans le tableau correspond à un filtre "AND".<br>Chaque entrée doit avoir 2 clés : </p><ul><li>type</li><li>values</li></ul><p>La clé "values" peut être une chaine ou un tableau de valeurs (filtre "OR").<br>Format :<br>[</p><p>    {<br>        "type": "role",<br>        "values":"users"<br>    },   <br>    {<br>        "type": "groups_name",<br>        "values":"RPS"<br>    },    </p><p>    {<br>        "type": "groups_name",<br>        "values":["vol","sin"]<br>    },     </p><p>    {<br>        "type": "groups_id",<br>        "values":"9c445054-c2f0-46c4-b784-ae6ea4c3ebbe"<br>    }<br>]<br></p></td><td></td></tr></tbody></table>

**Réponse**

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

<pre class="language-json"><code class="lang-json"><strong>{
</strong>  "data": [
    {
      "id": "string",
      "firstname": "string",
      "lastname": "string",
      "email": "string",
      "role": "string",
      "company": "string",
      "phone": "string",
      "source": "string",
      "enable_ranking": boolean,
      "lang": "string",
      "groups": [
        {
          "id": "string",
          "name": "string"
        }
      ]
    },
    {
      (...)
    }
  ],
  "links": {
    "first": "https://api.cards-microlearning.com/v1/users?page=1",
    "last": "https://api.cards-microlearning.com/v1/users?page=52",
    "prev": null,
    "next": "https://api.cards-microlearning.com/v1/users?page=2"
  },
  "meta": {
    "current_page": int,
    "from": int,
    "last_page": int,
    "links": [
      {
        "url": null,
        "label": "&#x26;laquo; Previous",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users?page=1",
        "label": "1",
        "active": true
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users?page=2",
        "label": "2",
        "active": false
      },
      {
        "url": null,
        "label": "...",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users?page=51",
        "label": "51",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users?page=52",
        "label": "52",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users?page=2",
        "label": "Next &#x26;raquo;",
        "active": false
      }
    ],
    "path": "https://api.cards-microlearning.com/v1/users",
    "per_page": int,
    "to": int,
    "total": int
  }
}
</code></pre>

{% endtab %}

{% tab title="401" %}

```json
{
  "message": "Unauthenticated."
}
```

{% endtab %}

{% tab title="403" %}

```json
{
  "message": "Incorrect domain"
}
```

{% endtab %}
{% endtabs %}

## Récupérer un utilisateur par son identifiant

<mark style="color:green;">GET</mark> `https://api.cards-microlearning.com/v1/users/<id_utilisateur>`

Récupérer les information d'un seul utilisateur

**Entête (Headers)**

| Name          | Value                                    |
| ------------- | ---------------------------------------- |
| Content-Type  | `application/json`                       |
| Authorization | `Bearer <token>`                         |
| X-Tenant      | `<Identifiant de votre espace (Tenant)>` |

**Réponse**

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

```json
{
  "data": {
    {
      "id": "string",
      "firstname": "string",
      "lastname": "string",
      "email": "string",
      "role": "string",
      "company": "string",
      "phone": "string",
      "source": "string",
      "enable_ranking": boolean,
      "lang": "string",
      "groups": [
        {
          "id": "string",
          "name": "string"
        }
      ]
    }
  }
}
```

{% endtab %}

{% tab title="401" %}

```json
{
  "message": "Unauthenticated."
}
```

{% endtab %}

{% tab title="403" %}

```json
{
  "message": "Incorrect domain"
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "message": "User doesn't exist",
  "type": "user"
}
```

{% endtab %}
{% endtabs %}

## Création d'un nouvel utilisateur

`POST` `https://api.cards-microlearning.com/v1/users`

Créer un nouvel utilisateur sur Cards

**Entête (Headers)**

| Name          | Value                                    |
| ------------- | ---------------------------------------- |
| Content-Type  | `application/json`                       |
| Authorization | `Bearer <token>`                         |
| X-Tenant      | `<Identifiant de votre espace (Tenant)>` |

**Body**

{% tabs %}
{% tab title="Text/JSON" %}

```json
{
  "firstname": "string",
  "lastname": "string",
  "email": "string",
  "lang": "string",
  "source": "string",
  "phone":"string",
  "company": "string",
  "role": "string", 
  "enable_ranking": boolean,
  "groups": [
    {
      "id":"string",
      "name": "string"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

Les champs obligatoires sont :&#x20;

* firstname&#x20;
* lastname&#x20;
* email

Les contraintes appliquées aux valeurs sont :

* firstname : longueur 190 charactères
* lastname : longueur 190 charactères
* company: firstname : longueur 190 charactères
* lang : fr | en
* source : app | sso | GoogleOAuth | MicrosoftOAuth | AppleOAuth
* role : user | editor | owner
* enable\_ranking : 0 ou 1 (false ou true)
* groups : Tableau de valeurs composé d'un ID et/ou d'un nom. Si l'ID est précisé, il est prioritaire sur le nom. Si le groupe n'existe pas et qu'un nom est donnée, le groupe sera créé automatiquement. Sinon le groupe sera ignoré.

Si tout se passe bien, l'objet de l'utilisateur créé sera renvoyé

**Réponse**

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

```json
{
  "data": {
    {
      "id": "string",
      "firstname": "string",
      "lastname": "string",
      "email": "string",
      "role": "string",
      "company": "string",
      "phone": "string",
      "source": "string",
      "enable_ranking": boolean,
      "lang": "string",
      "groups": [
        {
          "id": "string",
          "name": "string"
        }
      ]
    }
  }
}
```

{% endtab %}

{% tab title="401" %}

```json
{
  "message": "Unauthenticated."
}
```

{% endtab %}

{% tab title="403" %}

```json
{
  "message": "Incorrect domain"
}
```

{% endtab %}

{% tab title="422" %}

```json
{
  "message": "The firstname field is required. (and 2 more errors)",
  "errors": {
    "firstname": [
      "The firstname field is required."
    ],
    "lastname": [
      "The lastname field is required."
    ],
    "email": [
      "The email field is required."
    ]
  }
}
```

{% endtab %}
{% endtabs %}

## Mise à jour d'un utilisateur

<mark style="color:orange;">`PUT`</mark> `https://api.cards-microlearning.com/v1/users/<id_utilisateur>`

Mettre à jour les champs de son choix pour un utilisateur.\
Un champ non ajouté au BODY sera ignoré.\
Un champ vide en revanche supprimera la valeur du champ en question.\
Par exemple, si le champ "groups" est omis, les groupes actuelles seront gardés.\
Si "groups" est ajouté mais vide, tous les groupes pour cet utilisateurs seront retirés.

**Entête (Headers)**

| Name          | Value                                    |
| ------------- | ---------------------------------------- |
| Content-Type  | `application/json`                       |
| Authorization | `Bearer <token>`                         |
| X-Tenant      | `<Identifiant de votre espace (Tenant)>` |

**Body**

{% tabs %}
{% tab title="Text/JSON" %}

```json
{
  "firstname": "string",
  "lastname": "string",
  "lang": "string",
  "source": "string",
  "phone":"string",
  "company": "string",
  "role": "string", 
  "enable_ranking": boolean,
  "groups": [
    {
      "id":"string",
      "name": "string"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

**Aucun champs n'est obligatoire.**

Les contraintes appliquées aux valeurs sont :

* firstname : longueur 190 charactères
* lastname : longueur 190 charactères
* company: firstname : longueur 190 charactères
* lang : fr | en
* source : app | sso | GoogleOAuth | MicrosoftOAuth | AppleOAuth
* role : user | editor | owner
* enable\_ranking : 0 ou 1 (false ou true)
* groups : Tableau de valeurs composé d'un ID et/ou d'un nom. Si l'ID est précisé, il est prioritaire sur le nom. Si le groupe n'existe pas et qu'un nom est donnée, le groupe sera créé automatiquement. Sinon le groupe sera ignoré.

Si tout se passe bien, l'objet de l'utilisateur créé sera renvoyé

**Réponse**

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

```json
{
  "data": {
    {
      "id": "string",
      "firstname": "string",
      "lastname": "string",
      "email": "string",
      "role": "string",
      "company": "string",
      "phone": "string",
      "source": "string",
      "enable_ranking": boolean,
      "lang": "string",
      "groups": [
        {
          "id": "string",
          "name": "string"
        }
      ]
    }
  }
}
```

{% endtab %}

{% tab title="401" %}

```json
{
  "message": "Unauthenticated."
}
```

{% endtab %}

{% tab title="403" %}

```json
{
  "message": "Incorrect domain"
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "message": "User doesn't exist",
  "type": "update"
}
```

{% endtab %}

{% tab title="422" %}

```json
{
  "message": "The selected source is invalid.",
  "errors": {
    "source": [
      "The selected source is invalid."
    ]
  }
}
```

{% endtab %}
{% endtabs %}

## Suppression d'un utilisateur

<mark style="color:red;">`DELETE`</mark> `https://api.cards-microlearning.com/v1/users/<id_utilisateur>`

Supprimer toutes les données d'un utilisateur (profile et parcours de formation).

**Entête (Headers)**

| Name          | Value                                    |
| ------------- | ---------------------------------------- |
| Content-Type  | `application/json`                       |
| Authorization | `Bearer <token>`                         |
| X-Tenant      | `<Identifiant de votre espace (Tenant)>` |

**Response**

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

```json
{
  "message": "User has been removed"
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "message": "User doesn't exist",
  "type": "remove"
}
```

{% endtab %}
{% endtabs %}

## Listing des badges d'un utilisateur

<mark style="color:green;">GET</mark> `https://api.cards-microlearning.com/v1/users/<id_user>/badges`

Récupération d'une liste de badges débloqués pour un utilisateur.&#x20;

Cette liste peut être filtrée et est paginée.

**Entête (Headers)**

| Name          | Value                                    |
| ------------- | ---------------------------------------- |
| Content-Type  | `application/json`                       |
| Authorization | `Bearer <token>`                         |
| X-Tenant      | `<Identifiant de votre espace (Tenant)>` |

**Paramètre de l'url**

<table><thead><tr><th width="155">Nom</th><th width="124">Type</th><th width="315">Description</th><th width="166">Valeurs</th></tr></thead><tbody><tr><td><code>paginate</code></td><td>Nombre entier</td><td>Nombre d'élément dans la liste par page</td><td>Défaut : 100<br>Max : 500</td></tr><tr><td><code>filters</code></td><td>Tableau Json</td><td><p>Permet de filtrer sur des paramètre du badge comme : </p><ul><li>option_teasing</li><li>notif</li></ul><p>Chaque entrée dans le tableau correspond à un filtre "AND".<br>Chaque entrée doit avoir 2 clés : </p><ul><li>type</li><li>values</li></ul><p>La clé "values" peut être une chaine ou un tableau de valeurs (filtre "OR").<br>Format :<br>[</p><p>    {<br>        "type": "option_teasing",<br>        "values": 0<br>    },   <br>    {<br>        "type": "notif",<br>        "values": 1<br>    }<br>]<br></p></td><td></td></tr></tbody></table>

**Response**

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

```json
{
  "data": [
    {
      "id": "string",
      "name": "string",
      "description": "string",
      "image": "url",
      "emoji": {
        "i": "emoji",
        "n": [
          "string",
        ],
        "r": "string",
        "t": "string",
        "u": "string"
      },
      "info_win": : {
        "en": "string",
        "fr": "string"
      },
      "created_at": "datetime",
      "updated_at": "datetime"
    },
    {
      (...)
    }
  ],
  "links": {
    "first": "https://api.cards-microlearning.com/v1/users/<id_user>/badges?page=1",
    "last": "https://api.cards-microlearning.com/v1/users/<id_user>/badges?page=5",
    "prev": null,
    "next": "https://api.cards-microlearning.com/v1/users/<id_user>/badges?page=2"
  },
  "meta": {
    "current_page": int,
    "from": int,
    "last_page": int,
    "links": [
      {
        "url": null,
        "label": "&laquo; Previous",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users/<id_user>/badges?page=1",
        "label": "1",
        "active": true
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users/<id_user>/badges?page=2",
        "label": "2",
        "active": false
      },
      {
        "url": null,
        "label": "...",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users/<id_user>/badges?page=4",
        "label": "4",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users/<id_user>/badges?page=5",
        "label": "Next &raquo;",
        "active": false
      }      
    ],
    "path": "https://api.cards-microlearning.com/v1/users/<id_user>/badges",
    "per_page": int,
    "to": int,
    "total": int
  }
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "message": "User doesn't exist"
}
```

{% endtab %}
{% endtabs %}

## Listing des certificats d'un utilisateur

<mark style="color:green;">GET</mark> `https://api.cards-microlearning.com/v1/users/<id_user>/certificates`

Récupération d'une liste de certificats débloqués pour un utilisateur.&#x20;

Cette liste peut être filtrée et est paginée.

**Entête (Headers)**

| Name          | Value                                    |
| ------------- | ---------------------------------------- |
| Content-Type  | `application/json`                       |
| Authorization | `Bearer <token>`                         |
| X-Tenant      | `<Identifiant de votre espace (Tenant)>` |

**Paramètre de l'url**

<table><thead><tr><th width="155">Nom</th><th width="124">Type</th><th width="315">Description</th><th width="166">Valeurs</th></tr></thead><tbody><tr><td><code>paginate</code></td><td>Nombre entier</td><td>Nombre d'élément dans la liste par page</td><td>Défaut : 100<br>Max : 500</td></tr><tr><td><code>filters</code></td><td>Tableau Json</td><td><p>Permet de filtrer sur des paramètre du certificat comme : </p><ul><li>option_teasing</li><li>notif</li></ul><p>Chaque entrée dans le tableau correspond à un filtre "AND".<br>Chaque entrée doit avoir 2 clés : </p><ul><li>type</li><li>values</li></ul><p>La clé "values" peut être une chaine ou un tableau de valeurs (filtre "OR").<br>Format :<br>[</p><p>    {<br>        "type": "option_teasing",<br>        "values": 0<br>    },   <br>    {<br>        "type": "notif",<br>        "values": 1<br>    }<br>]<br></p></td><td></td></tr></tbody></table>

**Response**

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

```json
{
  "data": [
    {
      "id": "string",
      "name": "string",
      "description": "string",
      "content": "string",
      "info_win": : {
        "en": "string",
        "fr": "string"
      },
      "created_at": "datetime",
      "updated_at": "datetime"
    },
    {
      (...)
    }
  ],
  "links": {
    "first": "https://api.cards-microlearning.com/v1/users/<id_user>/certificates?page=1",
    "last": "https://api.cards-microlearning.com/v1/users/<id_user>/certificates?page=5",
    "prev": null,
    "next": "https://api.cards-microlearning.com/v1/users/<id_user>/certificates?page=2"
  },
  "meta": {
    "current_page": int,
    "from": int,
    "last_page": int,
    "links": [
      {
        "url": null,
        "label": "&laquo; Previous",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users/<id_user>/certificates?page=1",
        "label": "1",
        "active": true
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users/<id_user>/certificates?page=2",
        "label": "2",
        "active": false
      },
      {
        "url": null,
        "label": "...",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users/<id_user>/certificates?page=4",
        "label": "4",
        "active": false
      },
      {
        "url": "https://api.cards-microlearning.com/v1/users/<id_user>/certificates?page=5",
        "label": "Next &raquo;",
        "active": false
      }      
    ],
    "path": "https://api.cards-microlearning.com/v1/users/<id_user>/certificates",
    "per_page": int,
    "to": int,
    "total": int
  }
}
```

{% endtab %}

{% tab title="404" %}

```
{
  "message": "User doesn't exist"
}
```

{% endtab %}
{% endtabs %}


---

# 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://docapi.cards-microlearning.com/ressources/users.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.
