Get all discounts tied to a functionId

Get all discounts tied to a functionId

Webwizzy
Shopify Partner
18 1 3

Hello, I have created a "Discounts Shipping - Function" through the CLI, I have successfully created an interface in the admin panel that saves data that are then read by run.graphql and used in run.ts

Thats mega awesome, however, I need to show a list of discounts issued from the functionId

 

Basically I need all automatic shipping discount data issued from a specific function id, is that possible?

I created this:

query {
  discountNodes(first: 10) {
    nodes {
      id
      discount {
        __typename
        ... on DiscountAutomaticApp {
          title
          startsAt
          endsAt
          status
          discountId
          appDiscountType {
          	title
            functionId
        	}
          combinesWith {
            orderDiscounts
            productDiscounts
            shippingDiscounts
          }
        }
      }
    }
  }
}

 


That renders something similar to:

{
  "data": {
    "discountNodes": {
      "nodes": [
        {
          "id": "gid://shopify/DiscountCodeNode/1691885633862",
          "discount": {
            "__typename": "DiscountCodeBasic"
          }
        },
        {
          "id": "gid://shopify/DiscountCodeNode/1695324504390",
          "discount": {
            "__typename": "DiscountCodeFreeShipping"
          }
        },
        {
          "id": "gid://shopify/DiscountAutomaticNode/1695540904262",
          "discount": {
            "__typename": "DiscountAutomaticApp",
            "title": "Discount - Shipping",
            "startsAt": "2022-06-22T00:00:00Z",
            "endsAt": null,
            "status": "ACTIVE",
            "discountId": "gid://shopify/DiscountAutomaticNode/1695540904262",
            "appDiscountType": {
              "title": "Discount - Shipping",
              "functionId": "536930e4-1f2d-439e-9652-832624434e62"
            },
            "combinesWith": {
              "orderDiscounts": true,
              "productDiscounts": true,
              "shippingDiscounts": false
            }
          }
        },
        {
          "id": "gid://shopify/DiscountAutomaticNode/1695630000454",
          "discount": {
            "__typename": "DiscountAutomaticFreeShipping"
          }
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 18,
      "actualQueryCost": 8,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1992,
        "restoreRate": 100
      }
    }
  }
}


I could use the above and just map/filter the result and only keep the ones with the functionId of: "536930e4-1f2d-439e-9652-832624434e62"

The problem is, that's redundant, right? That cant possibly be the "best/better" way to do it?

 

 

Can someone help me with a more performant query that only gets the discounts tied to a specific functionId? 🙂

Fullstack Developer - Founder of the cryptocurrency market data aggregator, https://www.bitculator.com
Replies 3 (3)

Webwizzy
Shopify Partner
18 1 3

For some reason, this is only returning DiscountAutomaticFreeShipping created from the normal discounts and not the ones from the app?

 

 

query {
  automaticDiscountNodes(first:10){
    nodes{
      automaticDiscount{
        __typename
        ... on DiscountAutomaticFreeShipping{
          title
        }
      }
    }
  }
}

 

 


The above only return this:

 

 

{
  "data": {
    "automaticDiscountNodes": {
      "nodes": [
        {
          "automaticDiscount": {
            "__typename": "DiscountAutomaticFreeShipping",
            "title": "gfsdfg dg"
          }
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 4,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1996,
        "restoreRate": 100
      }
    }
  }
}

 

 

For some reason, this is only returning DiscountAutomaticFreeShipping created from the normal discounts and not the ones from the app?

 

 

 

Discounts.png

 

Fullstack Developer - Founder of the cryptocurrency market data aggregator, https://www.bitculator.com
heddykhalifa
Shopify Partner
236 18 53

Hey there,

 

Heddy from Gameball: Loyalty Program & VIP here!

 

To retrieve all discounts tied to a specific function ID in Shopify, you can use the Admin API. While there isn't a direct endpoint for filtering discounts by function ID, you can query the discounts endpoint and examine their attributes to identify which ones are associated with your desired function. This approach will help you gather the relevant information effectively.

Webwizzy
Shopify Partner
18 1 3

That can't be true, can it? That seems extremely inefficient

Fullstack Developer - Founder of the cryptocurrency market data aggregator, https://www.bitculator.com