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

# Create a product

> Create one product with one price.

Authenticate with an API key that belongs to the target organization and has Full access or the `products:products:write` permission. Only the Owner and Admin roles can grant it.

* Takes the same inputs as creating a product in the dashboard: one product with one price.
* Unlike the dashboard, it doesn't create a payment link. To get a shareable URL, [create a payment link](https://docs.anyway.sh/api-reference/endpoint/create-product-payment-link.md) for the product, or sell the price with a checkout session (see below).
* Send a unique `Idempotency-Key` header (required; 1–255 ASCII characters from `0x21` to `0x7E`, no spaces), the same rule as checkout sessions. The same key with the same body returns the product created the first time (`201`) and creates nothing new. The same key with a different body returns `409`. If the product created with that key was later deleted, a retry also returns `409`; send a new key.
* `pricingType` is `ONE_TIME` or `SUBSCRIPTION`. `pricing` is a string in major units, such as `"19.99"`. Omit `pricing` for a flexible "pay what you want" price; this works for `ONE_TIME` only, and `minAmount` and `maxAmount` are then optional.
* A `SUBSCRIPTION` price needs `billingInterval` (`DAY`, `MONTH` or `YEAR`). `billingIntervalCount` is optional and defaults to `1`.
* `status` is `PUBLISHED` (default), `DRAFT` or `ARCHIVED`. A `DRAFT` product can't be [published](https://docs.anyway.sh/api-reference/endpoint/publish-product.md) or [archived](https://docs.anyway.sh/api-reference/endpoint/archive-product.md) later. To keep a product off sale for now, create it as `ARCHIVED` and publish it when ready.
* Unknown fields are rejected with `400`.
* To sell a fixed price, pass the returned `pricing.pricingId` as `pricingId` to [Create a checkout session](https://docs.anyway.sh/api-reference/checkout-sessions.md). Checkout sessions can't sell a flexible amount; for that, [create a payment link](https://docs.anyway.sh/api-reference/endpoint/create-product-payment-link.md).

| Status | Code | Meaning |
| - | - | - |
| `400` | | Validation failed: bad currency, a subscription without an interval, a flexible subscription, an amount of 0 or less, an unknown field, or a missing or invalid `Idempotency-Key`. |
| `401` | | The API key is missing or invalid. |
| `403` | `INSUFFICIENT_SCOPE` | The key lacks `products:products:write`. |
| `409` | `PRODUCT_CONFLICT` | The `Idempotency-Key` was already used with a different body, or the product it created was deleted. |
| `413` | `PAYLOAD_TOO_LARGE` | The request body is larger than 64 KB. |


## OpenAPI

````yaml api-reference/openapi.json POST /v1/product
openapi: 3.0.3
info:
  description: >-
    Organization-scoped commerce API for merchant backends: create and manage
    checkout sessions, and query commerce records.
  title: Anyway Merchant API
  contact: {}
  version: '1.0'
  x-source: anyway-backend-go
servers:
  - url: https://merchant-api-prod.anyway.sh
security: []
paths:
  /v1/product:
    post:
      tags:
        - products
      summary: Create a product
      description: >-
        Creates one product with one price, the same as creating a product in
        the dashboard. Requires Full access or the `products:products:write`
        permission. Send a unique `Idempotency-Key` (required): the same key
        with the same body returns the product created the first time (201); the
        same key with a different body, or a product deleted since, returns 409
        PRODUCT_CONFLICT. Unknown request fields return 400. To sell a fixed
        price, pass the returned `pricing.pricingId` as `pricingId` to `POST
        /v1/checkout-sessions`; a flexible amount needs a payment link.
      parameters:
        - description: >-
            Unique creation request key: 1-255 ASCII characters in the range
            0x21-0x7E (no spaces or control characters)
          name: Idempotency-Key
          in: header
          required: true
          schema:
            type: string
            minLength: 1
            maxLength: 255
      requestBody:
        required: true
        description: Product and price
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/product.CreateRequest'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/response.ApiResponse-product_CreatedProductResponse
        '400':
          description: >-
            Bad Request. Invalid currency, a subscription without a billing
            interval, a flexible subscription, an amount of 0 or less, an
            unknown field, or an invalid Idempotency-Key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
        '403':
          description: >-
            Forbidden. The API key lacks the required permission
            (INSUFFICIENT_SCOPE).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
        '409':
          description: >-
            Conflict. The Idempotency-Key was already used with a different body
            (PRODUCT_CONFLICT).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
        '413':
          description: Request body larger than 64 KB (`PAYLOAD_TOO_LARGE`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
      security:
        - APIKeyAuth: []
components:
  schemas:
    product.CreateRequest:
      type: object
      required:
        - name
        - pricingType
        - currency
      properties:
        name:
          type: string
          description: Product name
        description:
          type: string
        pricingType:
          $ref: '#/components/schemas/product.PricingType'
        currency:
          type: string
          description: Currency code, for example USD
        pricing:
          type: string
          description: >-
            Price in major units, for example "19.99". Omit for a flexible (pay
            what you want) price, which is ONE_TIME only.
        minAmount:
          description: Optional minimum for a flexible price (ONE_TIME only)
          type: number
        maxAmount:
          description: Optional maximum for a flexible price (ONE_TIME only)
          type: number
        pricingName:
          type: string
          description: Name of the price
        billingInterval:
          $ref: '#/components/schemas/product.BillingInterval'
        billingIntervalCount:
          type: integer
          description: Number of intervals between charges (SUBSCRIPTION). Defaults to 1.
        status:
          type: string
          enum:
            - PUBLISHED
            - DRAFT
            - ARCHIVED
          default: PUBLISHED
    response.ApiResponse-product_CreatedProductResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/product.CreatedProductResponse'
        error:
          $ref: '#/components/schemas/response.ErrorDetail'
        message:
          type: string
        success:
          type: boolean
    response.ApiResponse-any:
      type: object
      properties:
        data: {}
        error:
          $ref: '#/components/schemas/response.ErrorDetail'
        message:
          type: string
        success:
          type: boolean
    product.PricingType:
      type: string
      enum:
        - SUBSCRIPTION
        - ONE_TIME
      x-enum-varnames:
        - PricingTypeSubscription
        - PricingTypeOneTime
    product.BillingInterval:
      type: string
      enum:
        - DAY
        - MONTH
        - YEAR
      x-enum-varnames:
        - BillingIntervalDay
        - BillingIntervalMonth
        - BillingIntervalYear
    product.CreatedProductResponse:
      type: object
      properties:
        createdAt:
          type: string
        description:
          type: string
        id:
          description: 'Deprecated: use productId.'
          type: string
          deprecated: true
        name:
          type: string
        orgId:
          type: string
        paymentLinks:
          type: array
          items:
            $ref: '#/components/schemas/product.PaymentLinkResponse'
        productId:
          type: string
        status:
          type: string
        updatedAt:
          type: string
        pricing:
          $ref: '#/components/schemas/product.CreatedPricing'
    response.ErrorDetail:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
    product.PaymentLinkResponse:
      type: object
      properties:
        amount:
          type: number
          nullable: true
        createdAt:
          type: string
        currency:
          type: string
        flexibleAmount:
          type: boolean
        isActive:
          type: boolean
        name:
          type: string
        paymentLinkUrl:
          type: string
        pricingId:
          type: string
        pricingType:
          type: string
        provider:
          type: string
        title:
          type: string
        description:
          type: string
        minAmount:
          type: number
          nullable: true
        maxAmount:
          type: number
          nullable: true
        successUrl:
          type: string
          description: >-
            Where the customer is sent after paying. Empty when the Anyway
            receipt is used.
    product.CreatedPricing:
      type: object
      properties:
        pricingId:
          type: string
        currency:
          type: string
        pricing:
          type: number
          description: Price in major units. Absent for a flexible price.
        minAmount:
          type: number
        maxAmount:
          type: number
        pricingType:
          $ref: '#/components/schemas/product.PricingType'
        billingInterval:
          $ref: '#/components/schemas/product.BillingInterval'
        billingIntervalCount:
          type: integer
        pricingName:
          type: string
          description: Price name, omitted when empty.
  securitySchemes:
    APIKeyAuth:
      description: 'Merchant API key (format: ak_BASE64)'
      type: apiKey
      name: X-API-Key
      in: header

````

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