Automatic discount not being applied when created with API

When creating an automatic discount for specific customer groups using the API, the discount is not being automatically applied at checkout. This only happens when using the API for all steps. When creating it in the dashboard, the discount is correctly applied. Is this a bug or is something wrong in my request? Full steps are below.

I followed these steps

First I created a customer group
Request:

curl https://connect.squareup.com/v2/customers/groups \
  -X POST \
  -H 'Square-Version: 2024-12-18' \
  -H 'Authorization: Bearer ' \
  -H 'Content-Type: application/json' \
  -d '{
    "group": {
      "name": "Gogh 10"
    },
    "idempotency_key": "d1f213e2-b989-4365-8e51-4537f53a4d90"
  }'

Response:

{
  "group": {
    "id": "40K3DW3SNPESRV4VQKWAZ24YH5",
    "name": "Gogh 10",
    "created_at": "2025-01-20T21:17:05.047Z",
    "updated_at": "2025-01-20T21:17:05Z"
  }
}

Then I created a discount
Request:

curl https://connect.squareup.com/v2/catalog/object \
  -X POST \
  -H 'Square-Version: 2024-12-18' \
  -H 'Authorization: Bearer ' \
  -H 'Content-Type: application/json' \
  -d '{
    "idempotency_key": "86221040-60aa-4bbd-a22a-1b23667aedd5",
    "object": {
      "id": "#NewDiscount",
      "type": "DISCOUNT",
      "present_at_all_locations": true,
      "discount_data": {
        "amount_money": {
          "amount": 1000,
          "currency": "USD"
        },
        "discount_type": "FIXED_AMOUNT",
        "modify_tax_basis": "DO_NOT_MODIFY_TAX_BASIS",
        "name": "$10 off"
      }
    }
  }'

Response:

{
  "catalog_object": {
    "type": "DISCOUNT",
    "id": "5IV7I6VIBSUYA3NBXPAVG25W",
    "updated_at": "2025-01-20T21:19:51.314Z",
    "created_at": "2025-01-20T21:19:51.314Z",
    "version": 1737407991314,
    "is_deleted": false,
    "present_at_all_locations": true,
    "discount_data": {
      "name": "$10 off",
      "discount_type": "FIXED_AMOUNT",
      "amount_money": {
        "amount": 1000,
        "currency": "USD"
      },
      "modify_tax_basis": "DO_NOT_MODIFY_TAX_BASIS"
    }
  },
  "id_mappings": [
    {
      "client_object_id": "#NewDiscount",
      "object_id": "5IV7I6VIBSUYA3NBXPAVG25W"
    }
  ]
}

Next I created a product set
Request:

curl https://connect.squareup.com/v2/catalog/object \
  -X POST \
  -H 'Square-Version: 2024-12-18' \
  -H 'Authorization: Bearer ' \
  -H 'Content-Type: application/json' \
  -d '{
    "idempotency_key": "1ed03019-3f6c-4dd5-98ec-2f955c7c4619",
    "object": {
      "id": "#NewProductSet",
      "type": "PRODUCT_SET",
      "present_at_all_locations": true,
      "product_set_data": {
        "all_products": true,
        "name": "All Products"
      }
    }
  }'

Response:

{
  "catalog_object": {
    "type": "PRODUCT_SET",
    "id": "JTS7ODAXGMCSGZ657BGKNVL3",
    "updated_at": "2025-01-20T21:21:59.491Z",
    "created_at": "2025-01-20T21:21:59.491Z",
    "version": 1737408119491,
    "is_deleted": false,
    "present_at_all_locations": true,
    "product_set_data": {
      "name": "All Products",
      "all_products": true
    }
  },
  "id_mappings": [
    {
      "client_object_id": "#NewProductSet",
      "object_id": "JTS7ODAXGMCSGZ657BGKNVL3"
    }
  ]
}

Then I created a pricing rule
Request:

curl https://connect.squareup.com/v2/catalog/object \
  -X POST \
  -H 'Square-Version: 2024-12-18' \
  -H 'Authorization: Bearer ' \
  -H 'Content-Type: application/json' \
  -d '{
    "idempotency_key": "eeb55eb6-1157-435b-973a-e38923ec3257",
    "object": {
      "id": "#NewPricingRule",
      "type": "PRICING_RULE",
      "present_at_all_locations": true,
      "pricing_rule_data": {
        "customer_group_ids_any": [
          "40K3DW3SNPESRV4VQKWAZ24YH5"
        ],
        "discount_id": "5IV7I6VIBSUYA3NBXPAVG25W",
        "match_products_id": "JTS7ODAXGMCSGZ657BGKNVL3",
        "name": "New Pricing Rule"
      }
    }
  }'

Response:

{
  "catalog_object": {
    "type": "PRICING_RULE",
    "id": "B6QIVLIFAFPTOOJJXCHBMD4C",
    "updated_at": "2025-01-20T21:24:44.114Z",
    "created_at": "2025-01-20T21:24:44.114Z",
    "version": 1737408284114,
    "is_deleted": false,
    "present_at_all_locations": true,
    "pricing_rule_data": {
      "name": "New Pricing Rule",
      "discount_id": "5IV7I6VIBSUYA3NBXPAVG25W",
      "match_products_id": "JTS7ODAXGMCSGZ657BGKNVL3",
      "application_mode": "AUTOMATIC",
      "customer_group_ids_any": [
        "40K3DW3SNPESRV4VQKWAZ24YH5"
      ]
    }
  },
  "id_mappings": [
    {
      "client_object_id": "#NewPricingRule",
      "object_id": "B6QIVLIFAFPTOOJJXCHBMD4C"
    }
  ]
}

**Finally I added the group to a customer **
Request:

curl https://connect.squareup.com/v2/customers/XHV1GTC01130QF4WSVAH30EB3W/groups/40K3DW3SNPESRV4VQKWAZ24YH5 \
  -X PUT \
  -H 'Square-Version: 2024-12-18' \
  -H 'Authorization: Bearer ' \
  -H 'Content-Type: application/json'

Response (showed as 200)

{}

I also confirmed the group and discount is showing in customer’s profile

However the discount is not being applied at checkout. When I created the discount from the dashboard, it worked fine. Just not when going through the steps above using the API.

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Create Bundled Discounts
Create Volume Discounts
Apply Square-Defined Discounts to Orders

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

Update: I figured out that when creating the discount, pricing rule, and product set using the API, the discount is only automatically applied when there is an actual item added to the cart. If the merchant enters a custom amount, the discount is not applied. I’m assuming it’s the product set that would configure that? I put “all-products” as true assuming that would cover custom amounts. What is the right way to do this?

Another update: Creating a product set with “all-products” as true doesnt seem to be what I intended. Each time I add an item to the cart, a new discount is applied. So if the customer is in a customer group with $10 off, and 5 items are added to the cart, the $10 off is applied 5 times, totaling $50 off.

The experience I’m trying to create is an automatic discount applied to specific customers and apply it to the entire cart. Not individual items. I’m able to do this by configuring discounts and customer groups in the dashboard but I cant figure out how to do that with the API?

Sorry for all the updates but I keep uncovering more stuff! After looking at the response from a dashboard generated automatic discount, I found this:

{
  "objects": [
    {
      "type": "PRICING_RULE",
      "id": "VYYJLUVURBG73RVQWYAG4GJO",
      "updated_at": "2025-01-20T23:39:24.004Z",
      "created_at": "2025-01-20T23:39:24.045Z",
      "version": 1737416364004,
      "is_deleted": false,
      "present_at_all_locations": true,
      "pricing_rule_data": {
        "discount_id": "GDCC3FLMSPUNRCHG36KQZTW7",
        "match_products_id": "HOCGRESOMK7DJC2CWYSQVLFV",
        "application_mode": "AUTOMATIC",
        "discount_target_scope": "WHOLE_PURCHASE",
        "customer_group_ids_any": [
          "54a02f91-7212-4dba-9254-8666f8cbd57f"
        ],
        "disabled_pricing_sources": [
          "SQUARE_ONLINE"
        ]
      }
    },

The undocumented field is "discount_target_scope": "WHOLE_PURCHASE",

That seemed to be what I was looking for so I added it to my request and it seems like it’s working so far. Instead of applying the price rule to each individual item, it’s applying it to the entire cart. Is there a reason why this field is not documented? Will it be deprecated?

1 Like

Glad to see that you were able to make a lot of progress. Any undocumented field shouldn’t be relied on. Unfortunately we don’t have public roadmaps for undocumented fields. :slight_smile:

Thanks Bryan. Can you confirm discount_target_scope is actually undocumented and I didn’t just miss it in the docs? If it’s truly undocumented, is there another way I should be achieving the effect of an automatic, cart level discount instead of discounts applied to each item? This works when doing it manually for each discount on the dashboard, but cant figure it out using the API

Yes, it’s undocumented. You can apply a discount to an order an have it scoped to the entire order rather then adding a discount to each item. :slight_smile:

Can you share how? I don’t see that option when creating a pricing rule. When a specific customer is added to the transaction, I want the discount automatically applied.

When your creating the order do you have auto_apply_discounts set to true? :slight_smile:

@Bryan-Square I’m not creating the order via an API. The merchant creates the order from their POS. I’m only configuring discounts and customers from the API. So when the merchant checks a customer out using the POS, then adds a customer to the sale, the customer will be configured with a discount (done on my end). But the discount needs to apply to the cart, not repeated for each line item.

Hey sorry just following up on this one. Trying to nail down a solution for a potential client. The problem is creating an automatic discount for customer groups via the API applies the discount repeatedly to each line item. I need it to apply once to the cart as a whole.

Thanks for you help!