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

# Upsert products

> Upsert products and their embeddings, this endpoint creates and updates all products that are in the list and delete all products that are not in the list.

## Overview

Synchronize your entire product catalog with a product block. This endpoint creates new products, updates existing ones, and **deletes products not in the request** - providing a complete catalog sync.

⚠️ **Important**: Products not included in the request will be deleted from the block.

## Use Cases

* **Full Catalog Sync**: Replace entire catalog with current inventory
* **Nightly Sync**: Complete synchronization from e-commerce platform
* **Inventory Management**: Ensure only available products are in catalog
* **Clean Sync**: Remove discontinued products automatically

## Authentication

```
x-api-key: your_api_key_here
```

## Path Parameters

| Parameter       | Type   | Required | Description                     |
| --------------- | ------ | -------- | ------------------------------- |
| `promptBlockId` | string | Yes      | Product block ID to synchronize |

## Request Body

Array of product objects (no limit):

| Field         | Type   | Required | Description                                      |
| ------------- | ------ | -------- | ------------------------------------------------ |
| `name`        | string | Yes      | Product name                                     |
| `description` | string | Yes      | Natural language description for AI (max 8192)   |
| `price`       | number | Yes      | Product price (positive number)                  |
| `currency`    | string | Yes      | Currency code                                    |
| `type`        | string | Yes      | PRODUCT or SERVICE                               |
| `external_id` | string | Yes      | Your unique identifier                           |
| `file_url`    | string | No       | Product image URL                                |
| `sku`         | string | No       | Product SKU. Falls back to `sku` key in metadata |
| `metadata`    | array  | Yes      | Additional product data as key-value pairs       |

<Danger>
  **⚠️ DELETES PRODUCTS**: Any products in the block that are NOT in this
  request will be permanently deleted.
</Danger>

## Example Request

```bash theme={null}
curl --request POST \
  'https://api.vambe.me/api/public/product/upsert/block-abc123' \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: your_api_key_here' \
  --data-raw '[
    {
      "name": "Laptop Pro",
      "description": "High-performance laptop for professionals. 16GB RAM, 512GB SSD, Intel i7 processor. Perfect for development and creative work.",
      "price": 1299.99,
      "currency": "USD",
      "type": "PRODUCT",
      "external_id": "laptop-pro-001",
      "file_url": "https://shop.com/laptop.jpg",
      "sku": "LAPTOP-PRO-001",
      "metadata": [
        { "key": "brand", "value": "TechBrand" },
        { "key": "ram", "value": "16GB" },
        { "key": "storage", "value": "512GB" }
      ]
    }
  ]'
```

## Behavior

### What Happens

1. **Creates**: Products with new `external_id` are created
2. **Updates**: Products with existing `external_id` are updated
3. **Deletes**: Products in block but NOT in request are deleted
4. **AI Embeddings**: All products are re-indexed for AI search

### Example Scenario

**Before**: Block has products A, B, C
**Request**: Send products B (updated), D (new)
**After**: Block has products B (updated), D (new)
**Deleted**: Products A and C

## Error Responses

| Status Code | Description                |
| ----------- | -------------------------- |
| 400         | Bad Request - Invalid data |
| 401         | Unauthorized               |
| 403         | Forbidden                  |
| 404         | Product block not found    |
| 500         | Internal Server Error      |

## Related Endpoints

* [POST /api/public/product/create/{promptBlockId}](/reference/product/create-products) - Add without deleting
* [POST /api/public/product/delete/{promptBlockId}](/reference/product/delete-products) - Delete specific products
* [GET /api/public/product/product-blocks](/reference/product/get-product-blocks) - List blocks


## OpenAPI

````yaml post /api/public/product/upsert/{promptBlockId}
openapi: 3.0.0
info:
  title: Vambe AI API
  description: Vambe AI documentation
  version: '1.0'
  contact: {}
servers:
  - url: https://api.vambe.me
    description: Production Server
security: []
tags:
  - name: Vambe AI
    description: ''
paths:
  /api/public/product/upsert/{promptBlockId}:
    post:
      tags:
        - Product
      summary: Upsert products
      description: >-
        Upsert products and their embeddings, this endpoint creates and updates
        all products that are in the list and delete all products that are not
        in the list.
      operationId: PublicProductController_upsertProducts
      parameters:
        - name: promptBlockId
          required: true
          in: path
          description: The prompt block ID to upsert the products
          schema:
            type: string
        - name: x-api-key
          in: header
          description: API key needed to authorize the request
          required: true
          schema:
            type: string
      requestBody:
        required: true
        description: The payload to send with the products
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublicUpsertProducts'
      responses:
        '201':
          description: Products upserted successfully.
        '400':
          description: Bad request.
        '401':
          description: Unauthorized.
        '403':
          description: Forbidden.
components:
  schemas:
    PublicUpsertProducts:
      type: array
      items:
        type: object
        properties:
          name:
            type: string
            minLength: 1
          file_url:
            type: string
          description:
            description: >-
              In the description you only need to add words that help the AI do
              a semantic search, avoide placing here prices, links or other type
              of data that is not natural language
            type: string
            minLength: 1
            maxLength: 8192
          type:
            type: string
            enum:
              - shopify
              - vambe
              - woocommerce
              - axis
              - vtex
              - jumpseller
              - odoo
              - tiendanube
              - magento
              - custom_app
            x-enumNames:
              - Shopify
              - Vambe
              - WooCommerce
              - Axis
              - Vtex
              - Jumpseller
              - Odoo
              - TiendaNube
              - Magento
              - CustomApp
          currency:
            type: string
            enum:
              - CLP
              - USD
              - MXN
              - BRL
              - UF
              - ARS
              - COP
              - UYU
              - PEN
              - EUR
              - HNL
              - BOB
              - PYG
              - GTQ
              - NIO
              - PAB
              - CRC
              - DOP
              - VES
              - BZD
              - SRD
              - GYD
            x-enumNames:
              - CLP
              - USD
              - MXN
              - BRL
              - UF
              - ARS
              - COP
              - UYU
              - PEN
              - EUR
              - HNL
              - BOB
              - PYG
              - GTQ
              - NIO
              - PAB
              - CRC
              - DOP
              - VES
              - BZD
              - SRD
              - GYD
          price:
            type: number
            minimum: 0
            exclusiveMinimum: false
          external_id:
            type: string
          sku:
            type: string
          metadata:
            type: array
            items:
              type: object
              properties:
                key:
                  type: string
                  minLength: 1
                value:
                  type: string
                  minLength: 1
              required:
                - key
                - value
        required:
          - name
          - description
          - type
          - currency
          - price
          - external_id
          - metadata

````