> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jelou.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# User cache

> Query and update the cache of a user

## Description

Manage the storage of data associated with a user within your bot.\
The **user cache** stores unique information about each person who interacts with your conversational experience and can be used within your workflows to:

* Associate operational data, such as an order number, to a `user`.
* Allow the bot to know user properties before the conversation begins.
* Store information needed to query internal or external services from specific workflows.

Additionally, the cache enables shortcuts for default bot actions, such as:

* Defining reactions or executing a workflow before the user initiates the conversation *(coming soon)*.

## Get User Cache

### Endpoint

```
GET https://api.jelou.ai/v1/users/{userId}/cache
```

### Path Parameters

<ParamField path="userId" type="string" required>
  User's phone number (without the `+` sign).
</ParamField>

### Query Parameters

<ParamField query="botId" type="string" required>
  Identifier of the bot associated with the user.
</ParamField>

### Request Example

```bash theme={null}
curl --request GET \
  --url 'https://api.jelou.ai/v1/users/{userId}/cache?botId=BOT_ID' \
  --header 'Authorization: Basic <Base64Encoded clientId:clientSecret>' \
  --header 'Content-Type: application/json'
```

### Response Example

The response may include any data previously stored in the user's cache.

```json theme={null}
{
  "groupId": "grp-67890",
  "orderNumber": "ORD-12345"
}
```

## Set user cache

### Endpoint

```bash theme={null}
POST https://api.jelou.ai/v1/users/{userId}/cache
```

### Path Parameters

<ParamField path="userId" type="string" required>
  User's phone number (without the `+` sign).
</ParamField>

### Request Body

<ParamField body="params" type="object">
  Object with the data that will be merged with the user's current cache.
</ParamField>

<ParamField body="botId" type="string" required>
  Identifier of the bot associated with the user.
</ParamField>

### Request Example

```bash theme={null}
curl --request POST \
  --url https://api.jelou.ai/v1/users/{userId}/cache \
  --header 'Authorization: Basic <Base64Encoded clientId:clientSecret>' \
  --header 'Content-Type: application/json' \
  --data '{
    "params": {
      "groupId": "grp-67890",
      "orderNumber": "ORD-12345"
    },
    "botId": "bot-12345"
  }'
```

### Response Example

```json theme={null}
{
  "message": [
    "User cache set successfully."
  ],
  "status": "success"
}
```

## Common Errors

* `400` - Could not get or update the user's status.
* `401` - Invalid or missing credentials.
* `404` - User or bot not found.
* `200` - Logic error when obtaining the cache (when status is "failed").

<Warning>
  The cache is merged with existing data. If you reuse already defined keys, their value will be overwritten. Make sure to maintain a consistent structure to avoid unexpected behavior in your workflows.
</Warning>
