> ## 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.

# Save records

> Create or update a user's memory records

## Description

Creates or updates the memory records of a user identified by `userReferenceId` and `botId`. Accepts a **maximum of 20 records** per request.

## Endpoint

```
POST https://gateway.jelou.ai/workflows/v2/memory/users/set
```

## Body parameters

<ParamField body="userReferenceId" type="string" required>
  The user's external reference identifier.
</ParamField>

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

<ParamField body="values" type="object" required>
  Map of key → record structure. The key is the variable name. Maximum 20 keys per request.

  Each record structure contains:

  * `value` (required) — value to store. Can be any JSON type.
  * `ttl` — variable TTL in seconds. Maximum `86400` (24h).
  * `contentType` — optional content type of the value.
</ParamField>

<Warning>
  Each value must be sent as an object `{ "value": ... }`. A plain value (for example `"paso": "confirmacion"`) is stored empty.
</Warning>

## Optional headers

<ParamField header="x-hash-ttl" type="integer">
  TTL in seconds for the user's entire memory hash.
</ParamField>

## Authentication

Every request must include the `x-api-key` header with an API key that has the `memory:write` scope.

```
x-api-key: API_KEY
```

## Request example

```bash cURL theme={null}
curl --request POST \
  --url https://gateway.jelou.ai/workflows/v2/memory/users/set \
  --header 'x-api-key: API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "userReferenceId": "USER_REFERENCE_ID",
    "botId": "BOT_ID",
    "values": {
      "paso": { "value": "confirmacion", "ttl": 3600 },
      "idioma": { "value": "es" }
    }
  }'
```

## Responses

| Code | Status                | Description                                                                                             |
| ---- | --------------------- | ------------------------------------------------------------------------------------------------------- |
| 201  | Created               | Records saved successfully.                                                                             |
| 401  | Unauthorized          | Invalid or missing authentication credentials.                                                          |
| 403  | Forbidden             | The API key does not have the `memory:write` scope.                                                     |
| 422  | Unprocessable Entity  | Required fields are missing, the format is invalid, or the maximum of 20 keys per request was exceeded. |
| 500  | Internal Server Error | Internal server error.                                                                                  |

## Response example

```json theme={null}
{
  "status": "success",
  "message": "Records created successfully",
  "data": "OK"
}
```


## OpenAPI

````yaml POST /v2/memory/users/set
openapi: 3.1.0
info:
  title: Jelou API
  description: >-
    API for the Jelou platform. Send messages, manage campaigns, handle
    conversations, users, databases, and widgets.
  version: 1.0.0
servers:
  - url: https://api.jelou.ai
    description: Production server
security:
  - basicAuth: []
tags:
  - name: Messages
    description: Send messages to users
  - name: Campaigns
    description: HSM campaigns and templates
  - name: Conversations
    description: Chat history and metrics
  - name: Users
    description: User state and cache management
  - name: Resources
    description: Media resource management
  - name: Datum
    description: Database CRUD operations
  - name: Widget
    description: Widget and room management
  - name: PMA Custom
    description: External support panel integration
  - name: Memory
    description: Per-user session memory management (Memory API v2)
paths:
  /v2/memory/users/set:
    servers:
      - url: https://gateway.jelou.ai/workflows
        description: Memory API
    post:
      tags:
        - Memory
      summary: Save records
      description: >-
        Creates or updates a user's memory records, identified by
        userReferenceId and botId. Accepts a maximum of 20 records per request.
      operationId: setMemoryRecords
      parameters:
        - name: x-hash-ttl
          in: header
          required: false
          description: TTL in seconds for the user's full memory hash. Optional.
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - userReferenceId
                - botId
                - values
              properties:
                userReferenceId:
                  type: string
                  description: External reference identifier of the user.
                botId:
                  type: string
                  description: Identifier of the bot associated with the memory.
                values:
                  type: object
                  description: >-
                    Map of key to record structure. The key is the variable
                    name. Maximum 20 keys per request.
                  maxProperties: 20
                  additionalProperties:
                    type: object
                    required:
                      - value
                    properties:
                      value:
                        description: Value to store. Any JSON type.
                      ttl:
                        type: integer
                        maximum: 86400
                        description: Variable TTL in seconds. Maximum 86400 (24h).
                      contentType:
                        type: string
                        description: Optional content type of the value.
      responses:
        '201':
          description: Records saved successfully.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - apiKey: []
components:
  responses:
    Unauthorized:
      description: Unauthorized - Invalid authentication credentials
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: >-
        Forbidden - The API key lacks the required scope (memory:read /
        memory:write)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UnprocessableEntity:
      description: Unprocessable entity - Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      properties:
        message:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        statusMessage:
          type: string
        status:
          type: integer
        error:
          type: object
          properties:
            code:
              type: string
            key:
              type: string
            description:
              type: string
            developerMessages:
              type: object
            clientMessages:
              type: object
        validationError:
          type: object
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: Basic authentication using Base64 encoded clientId:clientSecret
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: API key del proyecto de Jelou

````