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

# Upsert Inventory by External IDs

> Upsert inventory details for a product variant by location, identified using the commerce `external_id` values for the product, variant, and location. If the inventory exists, it will be updated; if it doesn't exist, it will be created.



## OpenAPI

````yaml put /inventories/external/products/{productExternalId}/variants/{variantExternalId}/locations/{locationExternalId}
openapi: 3.1.0
info:
  title: Inventories API
  description: >-
    API for managing inventories


    ### Resource identifier format


    Resource identifiers (the `id` field and related global-identifier fields)
    are returned as JSON

    integers by default. To receive them as strings instead, send the

    `X-Loop-Global-Identifier-Type: string` request header.
  version: v1
servers:
  - url: https://api.loopreturns.com/api/v1
security: []
tags:
  - name: Inventories
    description: Operations related to managing inventories
paths:
  /inventories/external/products/{productExternalId}/variants/{variantExternalId}/locations/{locationExternalId}:
    put:
      tags:
        - Inventories
      summary: Upsert Inventory by External IDs
      description: >-
        Upsert inventory details for a product variant by location, identified
        using the commerce `external_id` values for the product, variant, and
        location. If the inventory exists, it will be updated; if it doesn't
        exist, it will be created.
      operationId: upsertInventoryByExternalIds
      parameters:
        - in: path
          name: productExternalId
          schema:
            type: string
            maxLength: 64
            examples:
              - ex4mpl3-pr0duct
          required: true
          description: The identifier used by an external source to identify the product.
        - in: path
          name: variantExternalId
          schema:
            type: string
            maxLength: 64
            examples:
              - ex4mpl3-pr0duct-v4r14nt
          required: true
          description: >-
            The identifier used by an external source to identify the product
            variant.
        - in: path
          name: locationExternalId
          schema:
            type: string
            maxLength: 64
            examples:
              - ex4mpl3-l0c4t10n
          required: true
          description: The identifier used by an external source to identify the location.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateInventoryRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InventoryWrappedResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedResponse'
        '404':
          description: >-
            The product, product variant, or location could not be found. If no
            inventory record exists for the product variant and location pair,
            one is created and a 200 response is returned instead.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundResponse'
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorResponse'
      security:
        - write: []
components:
  schemas:
    UpdateInventoryRequest:
      type: object
      properties:
        available_count:
          type: integer
          format: int64
          description: The number of `product_variant`s available at `location`.
          examples:
            - 42
      required:
        - available_count
    InventoryWrappedResponse:
      type: object
      required:
        - inventory
      properties:
        inventory:
          $ref: '#/components/schemas/InventoryResponse'
    UnauthorizedResponse:
      type: object
      required:
        - errors
      properties:
        errors:
          type: string
          description: The message describing why the request was not authorized.
          examples:
            - Unauthorized.
    NotFoundResponse:
      type: object
      required:
        - message
      properties:
        message:
          type: string
          description: The message describing that the requested resource was not found.
          examples:
            - Resource not found.
    ValidationErrorResponse:
      type: object
      description: >-
        Returned when the request body fails validation. Uses Laravel's standard
        validation error shape.
      properties:
        message:
          type: string
          examples:
            - The available count field is required.
        errors:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
          examples:
            - available_count:
                - The available count field is required.
    InventoryResponse:
      type: object
      properties:
        available_count:
          type:
            - integer
            - 'null'
          format: int64
          description: The number of `product_variant`s available at `location`.
          examples:
            - 42
        product_variant:
          description: The details associated with the inventory's `product_variant`.
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/ProductVariantResponseData'
        location:
          description: The details associated with the inventory's `location`.
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/LocationResponseData'
    ProductVariantResponseData:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
          description: The unique identifier for the product variant, created by Loop.
          examples:
            - 674353902539857400
        external_id:
          type:
            - string
            - 'null'
          maxLength: 100
          description: >-
            The identifier used by an external source to identify the product
            variant.
          examples:
            - ex4mpl3-pr0duct-v4r14nt
        sku:
          type:
            - string
            - 'null'
          maxLength: 255
          description: The SKU of the product variant.
          examples:
            - EXAMPLEPRODUCT-VAR-1
        name:
          type: string
          maxLength: 255
          description: The name of the product variant.
          examples:
            - Example Product
        weight_grams:
          type:
            - integer
            - 'null'
          description: The weight of the product variant in grams.
          examples:
            - 444
        barcode:
          type:
            - string
            - 'null'
          maxLength: 255
          description: The barcode of the product variant.
          examples:
            - 23141001200513
    LocationResponseData:
      type: object
      required:
        - id
        - name
        - status
        - address
      properties:
        id:
          type: integer
          format: int64
          description: The unique identifier for the location, created by Loop.
          examples:
            - 680118439701923300
        external_id:
          type:
            - string
            - 'null'
          maxLength: 100
          description: The identifier used by an external source to identify the location.
          examples:
            - main-warehouse
        name:
          type: string
          maxLength: 45
          description: The name of the location.
          examples:
            - Main Warehouse
        status:
          type: string
          description: The status of the location.
          enum:
            - active
            - inactive
        address:
          $ref: '#/components/schemas/AddressResponseData'
          description: The address of the location.
    AddressResponseData:
      type: object
      properties:
        name:
          type:
            - string
            - 'null'
          maxLength: 100
          description: The name of the address.
          examples:
            - Main Warehouse
        company:
          type:
            - string
            - 'null'
          maxLength: 100
          description: The name of the company residing at the address.
          examples:
            - Universal Exports
        address1:
          type:
            - string
            - 'null'
          maxLength: 125
          description: Line 1 of the address.
          examples:
            - 1234 Example Street
        address2:
          type:
            - string
            - 'null'
          maxLength: 125
          description: Line 2 of the address.
          examples:
            - Unit 19
        city:
          type:
            - string
            - 'null'
          maxLength: 100
          description: The city in which the address is located.
          examples:
            - Townsville
        region:
          type:
            - string
            - 'null'
          maxLength: 100
          description: The state or region in which the address is located.
          examples:
            - Louisiana
        postal_code:
          type:
            - string
            - 'null'
          maxLength: 16
          description: The postal code associated with the address.
          examples:
            - 90210
        country_code:
          type:
            - string
            - 'null'
          maxLength: 2
          description: The country code associated with the address.
          examples:
            - US
  securitySchemes:
    write:
      name: X-Authorization
      type: apiKey
      in: header
      description: 'API Scope: "Inventory (write)"'

````