# Turn on a discount Function as an automatic discount

> Activate your discount Function in a store with discountAutomaticAppCreate: function handle, discount classes, combinations and a JSON config metafield.

Page: https://lintelagency.com/resources/graphql/function-backed-automatic-discount

## In short

A deployed discount Function does nothing until a discount uses it. To turn it on, call discountAutomaticAppCreate with a title, startsAt, the Function’s functionHandle, the discountClasses it affects (PRODUCT, ORDER or SHIPPING) and combinesWith. Pass settings as a JSON metafield on the discount; the Function reads it in its input query. For a code discount, use discountCodeAppCreate instead.

## Facts

- **API:** Admin GraphQL API
- **Operations:** shopifyFunctions, discountAutomaticAppCreate
- **Access scope:** write_discounts
- **API version:** 2026-10
- **Last checked:** 2 November 2026

## How to use it

1. Deploy the app with the discount Function. The handle is the one in the extension’s shopify.extension.toml.
2. Optionally list your app’s Functions with AppFunctions to confirm the handle on this store.
3. Send CreateVolumeDiscount with the handle, the classes the Function returns and how it combines with other discounts.
4. Put the merchant’s settings in a json metafield on the discount and read it in the Function’s input query.

## Code

### shopify-functions.graphql

```graphql
query AppFunctions($first: Int!) {
  shopifyFunctions(first: $first) {
    nodes {
      id
      handle
      title
      apiType
    }
  }
}
```

### shopify-functions.variables.json

```json
{
  "first": 25
}
```

### shopify-functions.response.json

```json
{
  "data": {
    "shopifyFunctions": {
      "nodes": [
        {
          "id": "00000000-0000-0000-0000-000000000000",
          "handle": "volume-discount",
          "title": "Volume discount",
          "apiType": "discount"
        }
      ]
    }
  }
}
```

### discount-automatic-app-create.graphql

```graphql
mutation CreateVolumeDiscount($discount: DiscountAutomaticAppInput!) {
  discountAutomaticAppCreate(automaticAppDiscount: $discount) {
    automaticAppDiscount {
      discountId
      title
      status
      startsAt
      discountClasses
      combinesWith {
        orderDiscounts
        productDiscounts
        shippingDiscounts
      }
    }
    userErrors {
      code
      field
      message
    }
  }
}
```

### discount-automatic-app-create.variables.json

```json
{
  "discount": {
    "title": "Buy 3, save 10%",
    "functionHandle": "volume-discount",
    "discountClasses": ["PRODUCT"],
    "startsAt": "2026-11-03T00:00:00Z",
    "combinesWith": {
      "orderDiscounts": false,
      "productDiscounts": false,
      "shippingDiscounts": true
    },
    "metafields": [
      {
        "namespace": "$app",
        "key": "function-configuration",
        "type": "json",
        "value": "{\"minimumQuantity\":3,\"percentage\":10}"
      }
    ]
  }
}
```

### discount-automatic-app-create.response.json

```json
{
  "data": {
    "discountAutomaticAppCreate": {
      "automaticAppDiscount": {
        "discountId": "gid://shopify/DiscountAutomaticNode/1234567890",
        "title": "Buy 3, save 10%",
        "status": "SCHEDULED",
        "startsAt": "2026-11-03T00:00:00Z",
        "discountClasses": ["PRODUCT"],
        "combinesWith": {
          "orderDiscounts": false,
          "productDiscounts": false,
          "shippingDiscounts": true
        }
      },
      "userErrors": []
    }
  }
}
```

## Limits and edge cases

- functionHandle only finds Functions in your own app; the app must be installed on the store.
- discountClasses sets which discount effects the discount can apply; list every class your Function returns.
- status is SCHEDULED until startsAt and ACTIVE after it.
- To change the settings later, write the metafield again with metafieldsSet, using the discount ID as ownerId.

## Questions

### How do I activate a Shopify discount Function?

Create a discount that uses it: discountAutomaticAppCreate for automatic discounts or discountCodeAppCreate for code discounts, with the Function’s functionHandle.

### How do I pass settings to a discount Function?

Save them as a JSON metafield on the discount when you create it, then read that metafield in the Function’s input query.

### Where do I find the function handle?

It is the handle in the Function extension’s TOML file. The shopifyFunctions query lists the handles of your app’s Functions on a store.

## Shopify documentation

- [discountAutomaticAppCreate](https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountAutomaticAppCreate)
- [Build a discount Function](https://shopify.dev/docs/apps/build/discounts/build-discount-function)

## Related

- [Tiered volume discount by quantity](https://lintelagency.com/resources/shopify-functions/tiered-volume-discount)
- [One discount Function, configured by metafield](https://lintelagency.com/resources/shopify-functions/metafield-configured-discount)
- [Configuring Functions with metafields, so rules change without deploys](https://lintelagency.com/journal/configuring-functions-with-metafields)
- [Shopify Scripts stopped running. Here is where each script’s logic goes now.](https://lintelagency.com/journal/shopify-scripts-to-functions)
- [Activate a delivery, payment or validation Function](https://lintelagency.com/resources/graphql/register-function-customization)

License: MIT. Free to use in your own store and in client work.
