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.

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

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.

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
query AppFunctions($first: Int!) {
  shopifyFunctions(first: $first) {
    nodes {
      id
      handle
      title
      apiType
    }
  }
}
shopify-functions.variables.json
{
  "first": 25
}
shopify-functions.response.json
{
  "data": {
    "shopifyFunctions": {
      "nodes": [
        {
          "id": "00000000-0000-0000-0000-000000000000",
          "handle": "volume-discount",
          "title": "Volume discount",
          "apiType": "discount"
        }
      ]
    }
  }
}
discount-automatic-app-create.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
{
  "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
{
  "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": []
    }
  }
}

Written by Lintel. MIT license: free to use in your own store and in client work.

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.
  • Validated against the Admin or Storefront API schema for version 2026-10 on the date shown. Check the version in your request URL.
  • IDs and store addresses in the examples are placeholders. Replace them with your own.
  • Admin API calls need an access token from your app. Never put an Admin API token in a storefront or theme.
  • MIT license. Use the code in your own store or in client work.

Need this built, tested and maintained for your store? See API integrations.

Have something to build? Let’s talk it through.

Taking a limited number of projects at a time. Every brief is read by an engineer, not a salesperson.

Gencer KarakayaShopify Engineer

An engineer reads your brief, and we reply by email.