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

# Create a product group

> Link products a customer can switch between. A product belongs to one group at a time: one in another group answers `409` with code `product_already_grouped`. An unknown product answers `400` with code `reference_not_found`. With an `external_id` the call is an upsert: it creates the group when the key is new (`201`) and updates the group that holds the key otherwise (`200`). Only the fields you send change, each with the meaning `PATCH /v1/product-groups/{id}` gives it; `products`, when sent, is the complete ordered member list. The request is compared with the stored group first, so a request that changes nothing answers `unchanged` and writes nothing, and retrying after a timeout is safe. The product group comes back with `write_result`. Send `If-None-Match: *` to create only.



## OpenAPI

````yaml post /v1/product-groups
openapi: 3.0.0
info:
  title: Creem API
  description: >-
    Creem is an all-in-one platform for managing subscriptions and recurring
    revenue, tailored specifically for today's SaaS companies. It enables you to
    boost revenue, enhance customer retention, and scale your operations
    seamlessly.
  version: v1
  contact:
    name: Creem Support
    url: https://creem.io
    email: support@creem.io
  license:
    name: Commercial
    url: https://creem.io/terms
  termsOfService: https://creem.io/terms
servers:
  - url: https://api.creem.io
    description: Production — live API for processing real transactions and data.
    x-speakeasy-server-id: prod
  - url: https://test-api.creem.io
    description: Test — sandbox API for development and testing with no real charges.
    x-speakeasy-server-id: test
security: []
tags: []
externalDocs:
  description: Creem Documentation
  url: https://docs.creem.io
paths:
  /v1/product-groups:
    post:
      tags:
        - Product Groups
      summary: Create a product group
      description: >-
        Link products a customer can switch between. A product belongs to one
        group at a time: one in another group answers `409` with code
        `product_already_grouped`. An unknown product answers `400` with code
        `reference_not_found`. With an `external_id` the call is an upsert: it
        creates the group when the key is new (`201`) and updates the group that
        holds the key otherwise (`200`). Only the fields you send change, each
        with the meaning `PATCH /v1/product-groups/{id}` gives it; `products`,
        when sent, is the complete ordered member list. The request is compared
        with the stored group first, so a request that changes nothing answers
        `unchanged` and writes nothing, and retrying after a timeout is safe.
        The product group comes back with `write_result`. Send `If-None-Match:
        *` to create only.
      operationId: createProductGroup
      parameters:
        - name: If-None-Match
          required: false
          in: header
          description: >-
            Send `*` to create only: when a product group of the store already
            has the `external_id`, the call answers `412`
            (`precondition_failed`) and writes nothing. Only `*` is accepted on
            a request with an `external_id` (any other value answers `400`);
            without one the header is ignored.
          schema:
            type: string
        - name: dry_run
          required: false
          in: query
          description: >-
            Send `true` to preview the write: the request runs as it would and
            is rolled back, so nothing is written. The answer is the one the
            real call would give: the same status (`201` for a create) and
            errors, and the product group with `write_result.dry_run` `true`.
            The id of a product group a dry run would create is never stored: a
            `GET` of it answers `404`. A product `id` or `external_id` that
            names no product of the store is a `reference_not_found` warning
            (`path`, `key`) instead of a `400`: on a create that entry is left
            out of the answer, and on an update the stored members stay as they
            are. `false` or no parameter is a real call; any other value answers
            `400`.
          schema:
            type: boolean
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateProductGroupRequestEntity'
      responses:
        '200':
          description: >-
            Only with an `external_id`: a product group of the store already had
            the key, and it was updated (`write_result.result` `updated`) or
            already matched the request (`unchanged`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProductGroupWriteResponseEntity'
        '201':
          description: The created product group (also by a dry run, which stores nothing)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProductGroupWriteResponseEntity'
        '400':
          description: Bad Request - Invalid input parameters
        '401':
          description: Unauthorized - Invalid or missing API key
        '404':
          description: Not Found - Resource does not exist
        '409':
          description: >-
            A product is already in another group (`product_already_grouped`). A
            key a group of the store holds is an update, not a conflict
        '412':
          description: >-
            Precondition failed (code `precondition_failed`): `If-None-Match: *`
            was sent and a product group of the store already has this
            `external_id`. `details.product_group_id` names it. Nothing is
            written.
        '422':
          description: >-
            A product of the group grants AI generation credits
            (`generation_credits_bundle_unavailable`). Nothing is changed.
        '503':
          description: >-
            Another request is changing this store's product groups
            (`product_groups_busy`); retry after `Retry-After`
      security:
        - ApiKey: []
components:
  schemas:
    CreateProductGroupRequestEntity:
      type: object
      properties:
        name:
          type: string
          description: >-
            The name of the product group, 3 to 255 characters. Required when
            creating a product group. On an existing group (by `external_id`) a
            different name renames it.
        description:
          type: string
          description: >-
            A description of the product group. On an existing group (by
            `external_id`), send `null` to clear it.
          nullable: true
        external_id:
          type: string
          description: >-
            Your own key for this product group. Unique per store,
            case-sensitive; 1 to 255 characters: letters, digits, `_`, `-`, `.`
            and `:`. With a key the call is an upsert: it creates the group when
            the key is new (`201`) and updates the group that holds it otherwise
            (`200`). Send `If-None-Match: *` to create only.
          example: pro-plans
        products:
          type: array
          description: >-
            The products of the group, in display order, each named by exactly
            one of `id` or `external_id`. Required when creating a product
            group, with at least one product. On an existing group (by
            `external_id`) it is the complete ordered member list: products it
            does not contain are removed, its order is the display order, and
            `[]` removes every member; omit it to leave the members unchanged. A
            product already in another group answers `409` with code
            `product_already_grouped`.
          items:
            oneOf:
              - $ref: '#/components/schemas/ProductGroupProductIdReferenceEntity'
              - $ref: >-
                  #/components/schemas/ProductGroupProductExternalIdReferenceEntity
          maxItems: 100
        upgrades_enabled:
          type: boolean
          description: >-
            Whether customers can switch between the products of this group.
            Defaults to `true` on a create.
        upgrade_behavior:
          type: string
          description: >-
            How a switch between the products of this group is billed. On an
            existing group (by `external_id`), send `null` to clear it.
          enum:
            - proration-charge-immediately
            - proration-charge
            - proration-none
          nullable: true
        upsells_enabled:
          type: boolean
          description: >-
            Whether the products of this group are offered as checkout upsells.
            Defaults to `true` on a create.
        is_active:
          type: boolean
          description: >-
            Whether the product group is active. Stored and returned; it does
            not yet stop upgrades or upsells. Defaults to `true` on a create.
    ProductGroupWriteResponseEntity:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for the object.
        mode:
          $ref: '#/components/schemas/EnvironmentMode'
        object:
          type: string
          description: >-
            String representing the object's type. Objects of the same type
            share the same value.
          example: product_group
        name:
          type: string
          description: The name of the product group.
        description:
          type: string
          description: A description of the product group.
          nullable: true
        external_id:
          type: string
          description: Your own key for this product group, or `null` when it has none.
          nullable: true
        products:
          description: >-
            The products in the group, in display order. A product is in one
            group at a time.
          type: array
          items:
            $ref: '#/components/schemas/ProductGroupProductEntity'
        upgrades_enabled:
          type: boolean
          description: Whether customers can switch between the products of this group.
        upgrade_behavior:
          type: string
          description: >-
            How a switch between the products is billed, or `null` for the
            default.
          enum:
            - proration-charge-immediately
            - proration-charge
            - proration-none
          nullable: true
        upsells_enabled:
          type: boolean
          description: Whether the products of this group are offered as checkout upsells.
        is_active:
          type: boolean
          description: >-
            Whether the product group is active. Stored and returned; it does
            not yet stop upgrades or upsells.
        created_at:
          format: date-time
          type: string
          description: Creation date of the product group.
          example: '2023-01-01T00:00:00Z'
        updated_at:
          format: date-time
          type: string
          description: Last updated date of the product group.
          example: '2023-01-01T00:00:00Z'
        write_result:
          description: What this write did and should tell you.
          allOf:
            - $ref: '#/components/schemas/ProductGroupWriteResultEntity'
      required:
        - id
        - mode
        - object
        - name
        - description
        - external_id
        - products
        - upgrades_enabled
        - upgrade_behavior
        - upsells_enabled
        - is_active
        - created_at
        - updated_at
        - write_result
    ProductGroupProductIdReferenceEntity:
      type: object
      properties:
        id:
          type: string
          description: The product ID.
          example: prod_4dGTkmBdnTnU9vV3KZ2Hcz
      required:
        - id
    ProductGroupProductExternalIdReferenceEntity:
      type: object
      properties:
        external_id:
          type: string
          description: The product's `external_id`.
          example: pro-monthly
      required:
        - external_id
    EnvironmentMode:
      type: string
      description: String representing the environment.
      enum:
        - test
        - prod
        - sandbox
    ProductGroupProductEntity:
      type: object
      properties:
        id:
          type: string
          description: The id of the product.
        external_id:
          type: string
          description: Your own key for the product, or `null` when it has none.
          nullable: true
      required:
        - id
        - external_id
    ProductGroupWriteResultEntity:
      type: object
      properties:
        result:
          type: string
          description: >-
            What the write did. Known values: `created`, `updated`, `unchanged`
            (the product group already was what the request asked for; nothing
            was written). More values can be added, so treat a value you do not
            know like `updated`.
          example: updated
        dry_run:
          type: boolean
          description: >-
            `true` when the request was sent with `dry_run=true`: nothing was
            written, and the id of a product group the write would have created
            is never stored. `false` on a real write. Stop unless it is `true`
            when you meant a dry run.
          example: false
        changes:
          description: What changed, field by field. Empty on a create and on `unchanged`.
          type: array
          items:
            $ref: '#/components/schemas/ProductGroupWriteChangeEntity'
        warnings:
          description: >-
            Things to know about this write. The write went through. Empty when
            there is nothing to report.
          type: array
          items:
            $ref: '#/components/schemas/ProductGroupWriteWarningEntity'
      required:
        - result
        - dry_run
        - changes
        - warnings
    ProductGroupWriteChangeEntity:
      type: object
      properties:
        path:
          type: string
          description: >-
            The field that changed, by its request name: `name`, `description`,
            `is_active`, `upgrades_enabled`, `upsells_enabled`,
            `upgrade_behavior`, `external_id` or `products`. A member change is
            one `products` entry whose `from` and `to` are the ordered lists of
            product ids, because the order is part of the value.
          example: products
        from:
          description: >-
            The value before the write: the field as a read returns it; for
            `products`, the ordered product ids.
          nullable: true
          oneOf:
            - type: string
            - type: number
            - type: boolean
            - type: array
              items: {}
            - type: object
              additionalProperties: true
          example:
            - prod_monthly
            - prod_yearly
        to:
          description: >-
            The value after the write: the field as a read returns it; for
            `products`, the ordered product ids.
          nullable: true
          oneOf:
            - type: string
            - type: number
            - type: boolean
            - type: array
              items: {}
            - type: object
              additionalProperties: true
          example:
            - prod_yearly
            - prod_monthly
      required:
        - path
        - from
        - to
    ProductGroupWriteWarningEntity:
      type: object
      properties:
        code:
          type: string
          description: >-
            What the warning is about. Known values: `reference_not_found` (a
            dry run only: the product key or id in `key`, sent in `path`, names
            no product of the store; the real call answers `400`
            `reference_not_found`. On a create the entry is left out of the
            group the dry run returns; on an update the stored members stay as
            they are). More values can be added, so ignore a code you do not
            know.
          example: reference_not_found
        path:
          type: string
          description: >-
            The entry the warning is about, for example
            `products[1].external_id`.
        key:
          type: string
          description: >-
            The key the warning is about. On `reference_not_found`, the id or
            key that names nothing.
      required:
        - code
        - path
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        API key for authentication. You can find your API key in the Creem
        dashboard under Settings > API Keys.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.