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

# Salvar registros

> Cria ou atualiza registros de memória de um usuário

## Descrição

Cria ou atualiza registros de memória de um usuário identificado por `userReferenceId` e `botId`. Aceita um **máximo de 20 registros** por solicitação.

## Endpoint

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

## Parâmetros do corpo

<ParamField body="userReferenceId" type="string" required>
  Identificador de referência externo do usuário.
</ParamField>

<ParamField body="botId" type="string" required>
  Identificador do bot associado à memória.
</ParamField>

<ParamField body="values" type="object" required>
  Mapa de chave → estrutura de registro. A chave é o nome da variável. Máximo de 20 chaves por solicitação.

  Cada estrutura de registro contém:

  * `value` (obrigatório) — valor a armazenar. Pode ser qualquer tipo JSON.
  * `ttl` — TTL da variável em segundos. Máximo `86400` (24h).
  * `contentType` — tipo de conteúdo opcional do valor.
</ParamField>

<Warning>
  Cada valor deve ser enviado como um objeto `{ "value": ... }`. Um valor simples (por exemplo `"paso": "confirmacion"`) é salvo vazio.
</Warning>

## Cabeçalhos opcionais

<ParamField header="x-hash-ttl" type="integer">
  TTL em segundos para o hash completo da memória do usuário.
</ParamField>

## Autenticação

Todas as requisições devem incluir o cabeçalho `x-api-key` com uma API key que tenha o scope `memory:write`.

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

## Exemplo de solicitação

```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" }
    }
  }'
```

## Respostas

| Código | Estado                | Descrição                                                                                                   |
| ------ | --------------------- | ----------------------------------------------------------------------------------------------------------- |
| 201    | Created               | Registros salvos com sucesso.                                                                               |
| 401    | Unauthorized          | Credenciais de autenticação inválidas ou ausentes.                                                          |
| 403    | Forbidden             | A API key não tem o scope `memory:write`.                                                                   |
| 422    | Unprocessable Entity  | Faltam campos obrigatórios, o formato é inválido ou foi ultrapassado o máximo de 20 chaves por solicitação. |
| 500    | Internal Server Error | Erro interno do servidor.                                                                                   |

## Exemplo de resposta

```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

````