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

# Update a Promotion

> Updates a Promotion



## OpenAPI

````yaml /api-reference/platform.yaml patch /api/v2/platform/promotions/{id}
openapi: 3.0.3
info:
  title: Platform API
  contact:
    name: Vendo Connect Inc.
    url: https://getvendo.com
    email: sales@getvendo.com
  description: Spree Platform API
  version: v2
servers:
  - url: http://{defaultHost}
    variables:
      defaultHost:
        default: localhost:3000
security: []
tags:
  - name: Addresses
  - name: Adjustments
  - name: Classifications
  - name: Countries
  - name: CMS Pages
  - name: CMS Sections
  - name: Digital Assets
  - name: Digital Links
  - name: Line Items
  - name: Menus
  - name: Menu Items
  - name: Option Types
  - name: Option Values
  - name: Orders
  - name: Payments
  - name: Payment Methods
  - name: Products
  - name: Promotions
  - name: Promotion Actions
  - name: Promotion Categories
  - name: Promotion Rules
  - name: Roles
  - name: Shipments
  - name: Shipping Categories
  - name: Shipping Methods
  - name: States
  - name: Stock Items
  - name: Stock Locations
  - name: Store Credit Categories
  - name: Store Credit Types
  - name: Store Credits
  - name: Tax Categories
  - name: Tax Rates
  - name: Taxons
  - name: Taxonomies
  - name: Users
  - name: Variants
  - name: Vendors
  - name: Webhook Events
  - name: Webhook Subscribers
  - name: Wishlists
  - name: Wished Items
  - name: Zones
paths:
  /api/v2/platform/promotions/{id}:
    patch:
      tags:
        - Promotions
      summary: Update a Promotion
      description: Updates a Promotion
      operationId: update-promotion
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
        - name: include
          in: query
          description: >-
            Select which associated resources you would like to fetch, see: <a
            href="https://jsonapi.org/format/#fetching-includes">https://jsonapi.org/format/#fetching-includes</a>
          example: promotion_category,promotion_rules,promotion_actions,stores
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/update_promotion_params'
                - $ref: '#/components/schemas/update_promotion_add_rule_params'
                - $ref: '#/components/schemas/update_promotion_update_rule_params'
                - $ref: '#/components/schemas/update_promotion_add_action_params'
                - $ref: '#/components/schemas/update_promotion_change_action_params'
                - $ref: >-
                    #/components/schemas/update_promotion_action_calculator_params
                - $ref: >-
                    #/components/schemas/update_promotion_change_calculator_params
      responses:
        '200':
          description: Record updated
          content:
            application/vnd.api+json:
              examples:
                Example:
                  value:
                    data:
                      id: '58'
                      type: promotion
                      attributes:
                        description: This is the new updated promo
                        expires_at: null
                        starts_at: null
                        name: 10% OFF
                        type: null
                        usage_limit: null
                        match_policy: all
                        code: RAND-10
                        advertise: false
                        path: null
                        created_at: '2022-11-08T19:35:04.723Z'
                        updated_at: '2022-11-08T19:35:04.970Z'
                        public_metadata: {}
                        private_metadata: {}
                      relationships:
                        promotion_category:
                          data:
                            id: '20'
                            type: promotion_category
                        promotion_rules:
                          data:
                            - id: '19'
                              type: promotion_rule
                        promotion_actions:
                          data:
                            - id: '42'
                              type: promotion_action
                        stores:
                          data:
                            - id: '396'
                              type: store
              schema:
                $ref: '#/components/schemas/resource'
        '401':
          description: Authentication Failed
          content:
            application/vnd.api+json:
              examples:
                Example:
                  value:
                    error: The access token is invalid
              schema:
                $ref: '#/components/schemas/error'
        '404':
          description: Record not found
          content:
            application/vnd.api+json:
              examples:
                Example:
                  value:
                    error: The resource you were looking for could not be found.
              schema:
                $ref: '#/components/schemas/error'
        '422':
          description: Invalid request
          content:
            application/vnd.api+json:
              examples:
                Example:
                  value:
                    error: Name can't be blank
                    errors:
                      name:
                        - can't be blank
              schema:
                $ref: '#/components/schemas/validation_errors'
      security:
        - bearer_auth: []
components:
  schemas:
    update_promotion_params:
      type: object
      properties:
        promotion:
          type: object
          properties:
            name:
              type: string
              example: Promotions Used in 2021
              description: Change the promotion a name.
            code:
              type: string
              example: CYB-MON
              nullable: true
              description: >-
                Change or remove the promotion code. Promotions without a code
                are automatically applied if the order meets the Promotion Rule
                requirements.
            description:
              type: string
              example: Save today with discount code XYZ at checkout.
              nullable: true
              description: Update the promotion a description.
            usage_limit:
              type: integer
              example: 100
              nullable: true
              description: If you wish you can set a usage limit for this promotion.
            advertise:
              type: boolean
            starts_at:
              type: string
              format: date_time
              nullable: true
              description: Set a date and time that this promotion begins.
            ends_at:
              type: string
              format: date_time
              nullable: true
              description: Set a date and time that this promotion ends.
            store_ids:
              type: array
              items:
                allOf:
                  - type: string
                    example: '2'
      required:
        - promotion
      title: Update a Promotion
      x-internal: false
    update_promotion_add_rule_params:
      type: object
      properties:
        promotion:
          type: object
          properties:
            promotion_rules_attributes:
              type: array
              items:
                allOf:
                  - properties:
                      type:
                        type: string
                        example: Spree::Promotion::Rules::Country
                        enum:
                          - Spree::Promotion::Rules::Country
                          - Spree::Promotion::Rules::ItemTotal
                          - Spree::Promotion::Rules::Product
                          - Spree::Promotion::Rules::User
                          - Spree::Promotion::Rules::FirstOrder
                          - Spree::Promotion::Rules::UserLoggedIn
                          - Spree::Promotion::Rules::OneUsePerUser
                          - Spree::Promotion::Rules::Taxon
                          - Spree::Promotion::Rules::OptionValue
                        description: Set the Promotion Rule type.
                      preferred_country_id:
                        type: integer
                        example: 122
                        description: >-
                          Each rule type has its own preferred attributes. In
                          this example we are setting the ID of the Country this
                          rule applies to. To learn more about Spree preferences
                          visit TODO: [LINK].
      required:
        - promotion
      title: Add a Rule to a Promotion
      x-internal: false
    update_promotion_update_rule_params:
      type: object
      properties:
        promotion:
          type: object
          properties:
            promotion_rules_attributes:
              type: array
              items:
                allOf:
                  - properties:
                      id:
                        type: string
                        example: '22'
                        description: >-
                          To update an existing Promotion Rule, you are required
                          to pass the ID of the rule you are updating.
                      type:
                        type: string
                        example: Spree::Promotion::Rules::Country
                        enum:
                          - Spree::Promotion::Rules::Country
                          - Spree::Promotion::Rules::ItemTotal
                          - Spree::Promotion::Rules::Product
                          - Spree::Promotion::Rules::User
                          - Spree::Promotion::Rules::FirstOrder
                          - Spree::Promotion::Rules::UserLoggedIn
                          - Spree::Promotion::Rules::OneUsePerUser
                          - Spree::Promotion::Rules::Taxon
                          - Spree::Promotion::Rules::OptionValue
                        description: Set the Promotion Rule type.
                      preferred_country_id:
                        type: integer
                        example: 143
                        description: >-
                          Each rule type has its own preferred attributes. In
                          this example we are changing the ID of the Country
                          this rule applies to. To learn more about Spree
                          preferences visit TODO: [LINK].
      required:
        - promotion
      title: Update an existing Rule
      x-internal: false
    update_promotion_add_action_params:
      type: object
      properties:
        promotion:
          type: object
          properties:
            promotion_actions_attributes:
              type: array
              items:
                allOf:
                  - properties:
                      type:
                        type: string
                        example: Spree::Promotion::Actions::CreateAdjustment
                        enum:
                          - Spree::Promotion::Actions::CreateAdjustment
                          - Spree::Promotion::Actions::CreateItemAdjustments
                          - Spree::Promotion::Actions::FreeShipping
                          - Spree::Promotion::Actions::CreateLineItems
                        description: Set the Promotion Action Type.
      required:
        - promotion
      title: Add an Action to a Promotion
      x-internal: false
    update_promotion_change_action_params:
      type: object
      properties:
        promotion:
          type: object
          properties:
            promotion_actions_attributes:
              type: array
              items:
                allOf:
                  - properties:
                      id:
                        type: string
                        example: '22'
                        description: >-
                          To update an existing Promotion Action, you are
                          required to pass the ID of the Promotion Action.
                      type:
                        type: string
                        example: Spree::Promotion::Actions::CreateAdjustment
                        enum:
                          - Spree::Promotion::Actions::CreateAdjustment
                          - Spree::Promotion::Actions::CreateItemAdjustments
                          - Spree::Promotion::Actions::CreateLineItems
                          - Spree::Promotion::Actions::FreeShipping
                        description: Set the Type of Promotion Action you wish to use.
      required:
        - promotion
      title: Change an Action Type
      x-internal: false
    update_promotion_action_calculator_params:
      type: object
      properties:
        promotion:
          type: object
          properties:
            promotion_actions_attributes:
              type: array
              items:
                allOf:
                  - properties:
                      id:
                        type: string
                        example: '22'
                        description: >-
                          To update an existing Promotion Action, you are
                          required to pass the ID of the action you wish to
                          update.
                      calculator_attributes:
                        properties:
                          id:
                            type: string
                            example: '19'
                            description: >-
                              To update an existing Action Calculator, you are
                              required to pass the ID of the calculator.
                          type:
                            type: string
                            example: Spree::Promotion::Actions::CreateAdjustment
                            enum:
                              - Spree::Promotion::Actions::CreateAdjustment
                              - Spree::Promotion::Actions::CreateItemAdjustments
                              - Spree::Promotion::Actions::CreateLineItems
                              - Spree::Promotion::Actions::FreeShipping
                            description: Set the Type of Promotion Action you wish to use.
                          preferred_flat_percent:
                            type: integer
                            example: 10
                            description: >-
                              In this example we are setting the preferred flat
                              percentage to `10`.
      required:
        - promotion
      title: Update an Action Calculator
      x-internal: false
    update_promotion_change_calculator_params:
      type: object
      properties:
        promotion:
          type: object
          properties:
            promotion_actions_attributes:
              type: array
              items:
                allOf:
                  - properties:
                      id:
                        type: string
                        example: '22'
                        description: >-
                          To update an existing Promotion Action, you are
                          required to pass the ID of the Promotion Action.
                      calculator_attributes:
                        properties:
                          type:
                            type: string
                            example: Spree::Calculator::FlatPercentItemTotal
                            enum:
                              - Spree::Calculator::FlatPercentItemTotal
                              - Spree::Calculator::FlatRate
                              - Spree::Calculator::FlexiRate
                              - Spree::Calculator::TieredPercent
                              - Spree::Calculator::TieredFlatRate
                              - Spree::Calculator::PercentOnLineItem
                            description: >-
                              To set the Promotion Action Calculator pass the
                              calculator type. Each Promotion action has certain
                              Calculators available, to learn more visit TODO:
                              [LINK]
      required:
        - promotion
      title: Change an Action Calculator
      x-internal: false
    resource:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/resource_properties'
      required:
        - data
      x-internal: false
    error:
      type: object
      properties:
        error:
          type: string
      required:
        - error
      x-internal: false
    validation_errors:
      type: object
      properties:
        error:
          type: string
        errors:
          type: object
      required:
        - error
        - errors
      x-internal: false
    resource_properties:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
        attributes:
          type: object
        relationships:
          type: object
      required:
        - id
        - type
        - attributes
      x-internal: false
  securitySchemes:
    bearer_auth:
      type: http
      scheme: bearer

````