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

> Upsert a collection, identified using the collection's `name` and `external_id`.



## OpenAPI

````yaml put /collections
openapi: 3.1.0
info:
  title: Collections API
  description: >-
    API for managing collections


    ### 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: Collections
paths:
  /collections:
    put:
      tags:
        - Collections
      summary: Upsert Collection
      description: >-
        Upsert a collection, identified using the collection's `name` and
        `external_id`.
      operationId: upsertCollection
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertCollectionRequest'
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CollectionWrappedResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedResponse'
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorResponse'
      security:
        - write: []
components:
  schemas:
    UpsertCollectionRequest:
      type: object
      properties:
        external_id:
          type: string
          maxLength: 64
          description: >-
            The identifier used by an external source to identify the
            collection.
          examples:
            - 1263csss-12uhsdfh-2138dja
        sales_channel:
          type: string
          maxLength: 255
          examples:
            - shopify
          description: >-
            If a channel with this name is not already associated with the shop,
            it will be used to create a new channel.
        name:
          type: string
          maxLength: 255
          description: The name of the collection.
          examples:
            - Footwear
        products:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/ProductRequestData'
          description: An array of products to add to the collection.
      required:
        - external_id
        - name
        - sales_channel
    CollectionWrappedResponse:
      type: object
      required:
        - collection
      properties:
        collection:
          $ref: '#/components/schemas/CollectionResponseData'
    UnauthorizedResponse:
      type: object
      required:
        - errors
      properties:
        errors:
          type: string
          examples:
            - Unauthorized.
    ValidationErrorResponse:
      type: object
      description: >-
        Returned when the request body fails validation. Uses Laravel's standard
        validation error shape.
      properties:
        message:
          type: string
          examples:
            - The name field is required.
        errors:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
          examples:
            - name:
                - The name field is required.
    ProductRequestData:
      description: >-
        A product to add to the collection, provided either as a plain integer
        global identifier or as an object with a `global_id`.
      oneOf:
        - type: integer
          description: The product's global identifier, provided as a plain integer.
        - type: object
          properties:
            global_id:
              type: integer
              description: The product's global identifier.
          required:
            - global_id
    CollectionResponseData:
      type: object
      required:
        - id
      properties:
        id:
          type: integer
          format: int64
          description: The unique identifier for the collection, created by Loop.
        external_id:
          type:
            - string
            - 'null'
          description: >-
            The identifier used by an external source to identify the
            collection.
        sales_channel:
          type:
            - string
            - 'null'
          description: The name of the channel.
        name:
          type:
            - string
            - 'null'
          description: The name of the collection.
        products:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/ProductResponse'
          description: An array of products associated with the collection.
    ProductResponse:
      title: ProductResponse
      type: object
      properties:
        id:
          type:
            - integer
            - 'null'
          format: int64
          minimum: 1
          examples:
            - 810772
          readOnly: true
        external_id:
          type:
            - string
            - 'null'
          examples:
            - 564400c7-7a6b-4f29-b6a5-7bb580b2992c
        sku:
          type:
            - string
            - 'null'
          examples:
            - SHOES-US44-M-Brwn
        name:
          type:
            - string
            - 'null'
  securitySchemes:
    write:
      name: X-Authorization
      type: apiKey
      in: header
      description: 'API Scope: "Collections (write)"'

````