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

# Register an add-to-cart event

> Registers that a product recommended by a specific widget was added to the cart



## OpenAPI

````yaml /openapi/recommendations-v1.yaml post /api/widget/{widget_id}/cart
openapi: 3.0.0
info:
  title: Recommendations API
  contact:
    name: Doofinder Support
    url: https://docs.doofinder.com/
  version: 1.0.0
  description: >
    # Introduction


    Recommendations API allows you to retrieve personalized product
    recommendations

    for your ecommerce website using Doofinder's recommendation engine.


    # Basics


    ## Endpoint


    All requests should be done with `https` protocol in our api location.

    `https://{search_zone}-recommendations.doofinder.com`

    where `{search_zone}` depends on your location, is the geographic zone your
    recommendation engine is located at.

    i.e.: eu1. Also, indicates which host to use in your API calls.


    ## Conventions


    Along most of the code samples you will find placeholders for some common
    variable values. They are:

    - `{widget_id}`: The recommendation widget's unique UUID. i.e.:
    123e4567-e89b-12d3-a456-426614174000

    - `{session_id}`: Session identifier for tracking user behavior. i.e.:
    b2b89619844f4eb0b5fa19f28a19d679

    - `{user_id}`: Unique user identifier. i.e.:
    8c80694b-354c-4533-acd1-e4b8e7d74b7b

    - `{hashid}`: The hash identifier for the search engine. i.e.:
    de8f052ea612f95b6950d4013dd6ef38


    ## Caveats


    ### Session IDs


    Some types of recommendations rely on user data to provide personalized
    product recommendations.

    If such data is not provided, the API will use fallback results, if fallback
    is enabled.

    If neither user data is provided nor fallback is enabled, then no
    recommendations will be returned.


    Currently, the **Browsing history** recommendation type is the only one that
    requires a `session_id` to be included in the request.


    ### CORS


    If CORS is enabled for your ecommerce site, it is important to ensure that
    the domain from which you make requests is correctly included

    in the request's `Origin` and/or `Referer` headers. This allows the domain
    to be validated against the list of allowed domains for your store.

    Otherwise, a **`403 Forbidden Origin`** will be returned, blocking the
    request for security reasons.


    ### Blocked IPs


    If the IP address from which the request originates is blacklisted in your
    store configuration, a **`403 Forbidden IP`**

    will be returned, blocking the request for security reasons.
  termsOfService: https://www.doofinder.com/es/terms-and-conditions
  x-logo:
    url: https://admin.doofinder.com/images/logo.svg
    backgroundColor: '#33268C'
    altText: Doofinder Recommendations Engine
servers:
  - url: https://{search_zone}-recommendations.doofinder.com
    variables:
      search_zone:
        enum:
          - eu1
          - us1
          - ap1
        default: eu1
security: []
tags:
  - name: Recommendations
    description: Recommendation operations for personalized product suggestions.
paths:
  /api/widget/{widget_id}/cart:
    post:
      tags:
        - Recommendations
      summary: Register an add-to-cart event
      description: >-
        Registers that a product recommended by a specific widget was added to
        the cart
      operationId: registerWidgetAddToCart
      parameters:
        - name: widget_id
          in: path
          required: true
          description: Unique identifier for the widget
          schema:
            type: string
            format: uuid
            example: 123e4567-e89b-12d3-a456-426614174000
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AddToCartRequest'
      responses:
        '200':
          description: Add-to-cart event processed, check the status field for the outcome
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - OK
                      - ERROR
                    example: OK
        '400':
          description: Bad Request - Missing required parameters or validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestError'
        '403':
          description: Forbidden - Access denied
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    enum:
                      - Forbidden origin
                      - Forbidden ip
                example:
                  error: Forbidden origin
        '404':
          description: Not Found - Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundError'
        '429':
          description: Too Many Requests - Rate limit exceeded
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Too many request
components:
  schemas:
    AddToCartRequest:
      type: object
      required:
        - session_id
        - dfid
        - title
        - price
      properties:
        session_id:
          type: string
          description: Session identifier for tracking user behavior
          example: b2b89619844f4eb0b5fa19f28a19d679
        dfid:
          type: string
          description: Doofinder's unique ID for the item added to the cart
          example: >-
            123e4567e89b12d3a456426614174000@product@e7b7a6c35b2d4afc94991bfc8100227a
        title:
          type: string
          description: The item title
        amount:
          type: integer
          description: Quantity added to the cart (optional, default 1)
          example: 1
        price:
          type: number
          format: float
          description: The item price
    BadRequestError:
      type: object
      properties:
        error:
          type: string
          description: General error message
          example: Bad request
        details:
          type: object
          description: Field-specific validation errors
          additionalProperties:
            type: array
            items:
              type: string
          example:
            session_id:
              - length must be less than or equal to 32
            user_id:
              - is required
            current_url:
              - is required
      required:
        - error
    NotFoundError:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Not found
        resource:
          type: string
          description: Type of resource that was not found
          example: Widget
        resource_id:
          type: string
          description: ID of the resource that was not found
          example: cc1e4567-e89b-12d3-a456-426614174000
      required:
        - error

````