• Promotions/
    Promotion Management/
    Create X for Amount Discount Promotion

    Create X for Amount Discount Promotion

    POST Create X for amount discount promotion

    https://api.moltin.com/v2/promotions/
    

    Line-item discounts are only supported by the line calculation method. For more information about this method, see the Calculation Method section.

    Parameters

    Headers

    NameRequiredTypeDescription
    AuthorizationRequiredstringThe Bearer token required to get access to the API.

    Body

    NameRequiredTypeDescription
    typeRequiredstringSpecifies the type of the resource. The type of resource for promotions is, promotion.
    nameRequiredstringSpecifies a name for the promotion.
    descriptionRequiredstringSpecifies a description for the promotion.
    enabledRequiredbooleanSpecifies whether the promotion is enabled. The options are true or false, and the default setting is false.
    automaticRequiredbooleanSpecifies whether the promotion is applied automatically to the cart or a code is required to apply the promotion. The default setting is false. When this value is set to true, a code is autogenerated. If this value is set to false, you must create the code manually. For more information about creating codes, see the Create Promotion Codes section.
    promotion_typeRequiredstringSpecifies the type of the promotion. Use x_for_amount for creating X for amount discount promotions.
    max_applications_per_cartOptionalintegerSpecifies the maximum number of application of a promotion per cart.
    min_cart_valueOptionalarraySpecifies an array of currency-value objects, min_cart_value[].currency and min_cart_value[].amount, that provide the minimum cart value required for the promotion to apply. You can add one or several value specifications in different currencies.
    schemaRequiredobjectSpecifies the promotion value, currency, and the products to be applied for the promotion. See the schema object.
    startRequiredstringSpecifies the start date and time of the promotion or the start date of the promotion. You can provide a specific time in the HH:MM format. For example, "start": "2000-01-01 12:00". If no time is specified, the default start and end time is set to 00:00.
    endRequiredstringSpecifies the end date and time of the promotion or the end date of the promotion.

    The schema object

    Promotions are defined by schemas that are used internally to verify promotions and calculate discounts. You must define a schema when you create the promotion. For more information, see the schema.exclude criteria and the targeting fields criteria.

    NameRequiredTypeDescription
    schema.xRequiredintegerSpecifies the required quantity value of the targeted SKU. For example, for a promotion 2 for 100 for a SKU, the X is the quantity of 2 and 100 is the price amount for the qualified SKU.
    schema.currencies[].amountRequiredintegerSpecifies the amount of the qualified SKU for the promotion. For example, for a promotion 2 for 100 for a SKU, 100 is the amount of the qualified SKU with quantity of 2.
    schema.currencies[].currencyRequiredstringSpecifies a three-letter currency code. For example, USD.
    schema.targetsRequiredarray [string]Specifies the product SKUs or unique identifiers of the products included in the promotion. You need to define schema.targets, schema.target_nodes or schema.target_attributes, or all three of them to qualify for this promotion.
    schema.target_nodesOptionalarray [string]Specifies the unique identifiers of the nodes to be applied for the promotion in addition to the product SKUs applied in schema.targets.
    schema.exclude.targetsOptionalarray [string]Specifies the product SKUs to be excluded from the promotion.
    schema.exclude.nodesOptionalarray [string]Specifies the unique identifiers of the nodes to be excluded from the promotion.
    schema.target_catalogsOptionalarray [string]Specifies the unique identifiers of the catalogs to be applied for this promotion. If you do not set this parameter, promotion will be applied to all catalogs.
    schema.target_attributes[].templateOptionalstringSpecifies the name of the template slug to be included in a promotion.
    schema.target_attributes[].fieldOptionalstringSpecifies the unique slug identifier for the field to be included in a promotion.
    schema.target_attributes[].typeOptionalstringSpecifies the type of the field, such as string, integer, boolean, float, or date.
    schema.target_attributes[].valueOptionalDepending on the type of the field, value can be string, integer, boolean, float, or date.Specifies the value of the field that was specified in the attributes.type. For example, you can specify any color in the value if you indicate color in the attributes.field.
    schema.exclude.attributes[].templateOptionalstringSpecifies the name of the template slug to be excluded from a promotion.
    schema.exclude.attributes[].fieldOptionalstringSpecifies the unique slug identifier for the field to be excluded from a promotion.
    schema.exclude.attributes[].typeOptionalstringSpecifies the type of the field, such as string, integer, boolean, float, or date .
    schema.exclude.attributes[].valueOptionalDepending on the type of the field, value can be string, integer, boolean, float, or date.Specifies the value of the field that was specified in the attributes.type. For example, you can specify any color in the value if you indicate color in the attributes.field.
    schema.target_conditionsOptionalarray [object]Specifies and/or conditions on nodes and attributes to be included in a promotion. For example, if you want to include t-shirts and pants that are blue or green in color from a promotion, the items that you wish to include should be in node-t-shirts or node-pants and have the color attribute with the value blue or green.
    schema.target_conditions.orOptionalarray [object]Specifies or conditions on nodes and attributes to be included in a promotion. You can include up to 10 and conditions inside an or array.
    schema.target_conditions.or[].andOptionalarray[object]Specifies and conditions on nodes and attributes to be included from the promotion. You can only have five items inside an andcondition.
    schema.target_conditions.or[].and[].nodeOptionalobjectIncludes values field to specify the unique identifiers of the nodes to be included in the promotion.
    schema.target_conditions.or[].and[].attributeOptionalobjectSpecifies template, field, type, and values of the attribute to be included in the promotion.
    schema.exclude.conditionsOptionalobjectSpecifies and/or conditions on nodes and attributes to be excluded from a promotion. For example, if you want to exclude t-shirts and pants that are blue or green in color from a promotion, the items that you wish to exclude should be in node-t-shirts or node-pants and have the color attribute with the value blue or green.
    schema.exclude.conditions.orOptionalarray [object]Specifies or conditions on nodes and attributes to be excluded from a promotion. You can include up to 10 and conditions inside an or array.
    schema.exclude.conditions.or[].andOptionalarray[object]Specifies and conditions on nodes and attributes to be excluded from a promotion. You can only have five items inside an andcondition.
    schema.exclude.conditions.or[].and[].nodeOptionalobjectIncludes values field to specify the unique identifiers of the nodes to be excluded from the promotion.
    schema.exclude.conditions.or[].and[].attributeOptionalobjectSpecifies template, field, type, and values of the attribute to be excluded from the promotion.

    Request Example

    curl -X POST https://api.moltin.com/v2/promotions \
    {
      "data": {
        "type": "promotion",
        "name": "PROMO EXAMPLE",
        "description": "2 for 100 promotion",
        "enabled": true,
        "automatic": false,
        "promotion_type": "x_for_amount",
        "max_applications_per_cart": 0,
        "schema": {
          "x": 2,
          "currencies": [
            {
              "amount": 10000,
              "currency": "USD"
            }
          ],
          "targets" : ["Sku1"],
          "target_nodes" :["{{nodeId}}"],
          "target_catalogs" : ["{{catalodId}}"],
          "target_attributes": [
              {
                  "template": "products(shoes)",
                  "field": "brand",
                  "type": "string",
                  "value": "adidas"
              }
              ],
           "target_conditions": {
                    "or": [
                        {
                            "and": [
                                {
                                    "node": {
                                        "values": [
                                            "928c9f9b-29a0-4a4a-b339-8b2e981a14ad",
                                            "1e969e87-80d3-4f1a-80d8-a2a301eac983",
                                            "08b58e20-70d1-4c37-b61f-d5315d492a60"
                                        ]
                                    }
                                },
                                {
                                    "attribute": {
                                        "template": "products(shoes)",
                                        "field": "brand",
                                        "type": "string",
                                        "values": [
                                            "puma"
                                        ]
                                    }
                                }
                            ]
                        }
                    ]
                },
                "exclude": {
                    "nodes" : ["nodes-id-1"],
                    "targets": ["sku"],
                    "attributes": [
                        {
                            "template": "products(shoes)",
                            "field": "brand",
                            "type": "string",
                            "value": "nike"
                        }
                    ],
                    "conditions": {
                        "or": [
                            {
                                "and": [
                                    {
                                        "node": {
                                            "values": [
                                                "1e969e87-80d3-4f1a-80d8-a2a301eac983"
                                            ]
                                        }
                                    },
                                    {
                                        "attribute": {
                                            "template": "products(shoes)",
                                            "field": "isResale",
                                            "type": "boolean",
                                            "values": [
                                                true
                                            ]
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }
            },
            "start": "2000-01-01",
            "end": "2100-01-01"
        }
    }
    

    Response Example

    201 Created

    {
        "data": {
            "type": "promotion",
            "id": "757e30ba-4164-4b31-93f2-6e639ce03e2d",
            "parent_id": "757e30ba-4164-4b31-93f2-6e639ce03e2d",
            "name": "PROMO EXAMPLE",
            "description": "2 for 100 promotion",
            "enabled": true,
            "current": true,
            "promotion_type": "x_for_amount",
            "schema": {
                "x": 2,
                "currencies": [
                    {
                        "currency": "USD",
                        "amount": 10000
                    }
                ],
                "targets": [
                    "Sku1"
                ],
                "target_nodes": [
                    "{{nodeId}}"
                ],
                "target_attributes": [
                    {
                        "template": "products(shoes)",
                        "field": "brand",
                        "type": "string",
                        "value": "adidas"
                    }
                ],
                "target_catalogs": [
                    "{{catalodId}}"
                ],
                "target_conditions": {
                    "or": [
                        {
                            "and": [
                                {
                                    "node": {
                                        "values": [
                                            "928c9f9b-29a0-4a4a-b339-8b2e981a14ad",
                                            "1e969e87-80d3-4f1a-80d8-a2a301eac983",
                                            "08b58e20-70d1-4c37-b61f-d5315d492a60"
                                        ]
                                    }
                                },
                                {
                                    "attribute": {
                                        "template": "products(shoes)",
                                        "field": "brand",
                                        "type": "string",
                                        "values": [
                                            "adidas"
                                        ]
                                    }
                                }
                            ]
                        }
                    ]
                },
                "exclude": {
                    "targets": [
                        "sku"
                    ],
                    "nodes": [
                        "nodes-id-1"
                    ],
                    "attributes": [
                        {
                            "template": "products(shoes)",
                            "field": "brand",
                            "type": "string",
                            "value": "nike"
                        }
                    ],
                    "conditions": {
                        "or": [
                            {
                                "and": [
                                    {
                                        "node": {
                                            "values": [
                                                "1e969e87-80d3-4f1a-80d8-a2a301eac983"
                                            ]
                                        }
                                    },
                                    {
                                        "attribute": {
                                            "template": "products(shoes)",
                                            "field": "isresale",
                                            "type": "boolean",
                                            "values": [
                                                true
                                            ]
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }
            },
            "start": "2000-01-01T00:00:00Z",
            "end": "2100-01-01T00:00:00Z",
            "created_by": "seller@elasticpath.com",
            "updated_by": "another_seller@elasticpath.com",
            "meta": {
                "timestamps": {
                    "created_at": "2023-02-02T14:29:14.907Z",
                    "updated_at": "2023-02-02T14:29:14.907Z"
                }
            }
        }
    }
    

    The schema.exclude criteria

    When creating a promotion, you can specify when it should not be applied. The promotion will not be applied on any cart (or cart item, depending on the promotion type) that fulfills at least one of the schema.exclude criteria. The following criteria can be set to exclude items from a promotion:

    • schema.exclude.targets
    • schema.exclude.nodes
    • schema.exclude.attributes
    • schema.exclude.conditions

    For example, if you want to create a promotion with value as SKU1 in schema.exclude.targets and and color yellow and size small in schema.exclude.attributes, then any products with SKU1 or the color yellow or the size small will be excluded from the promotion.

    To exclude products from a promotion based on multiple conditions at the same time, use schema.exclude.conditions. For example, use schema.exclude.conditions to exclude items that are both yellow in color and small in size.

    The targeting fields criteria

    When creating a promotion, you can also specify when it should be applied. To define the targeted products, use the following fields:

    • schema.target_catalogs
    • schema.targets
    • schema.target_nodes
    • schema.target_attributes
    • schema.target_conditions

    The cart item's catalog is verified if you define the schema.target_catalogs field. If the item is in any of the targeted catalogs specified in schema.target_catalogs, the promotion will be applied. If the item is not in any of the catalogs, the promotion will not be applied.

    Then, the cart item is verified to see if it fulfills at least one criteria of any of the four other targeting fields. In other words, the schema targeting fields such as schema.targets, schema.target_nodes, schema.target_attributes and schema.target_conditions create OR trageting conditions.

    For example, if you create a promotion with values as SKU1 in schema.targets and color yellow and size small in schema.target_attributes, then it will be applied to any products with SKU1 or the color yellow or the size small.

    To create a promotion that targets products based on multiple conditions at the same time, use schema.target_conditions. For example, use it to target items that are both yellow in color and small in size.

    Was this helpful?

    Previous
    Create X for Y Discount Promotion