Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Discount Code lookup endpoint REST API return 404 for discounts with new Buy X Get Y options

Solved

Discount Code lookup endpoint REST API return 404 for discounts with new Buy X Get Y options

AndriiMeretskyi
Shopify Partner
2 0 0

Discount Code lookup endpoint REST API return 404 for discounts with new Buy X Get Y option with minimum purchase amount https://andrii-sh10.myshopify.com/admin/api/2019-10/discount_codes/lookup.json?code=SpendXBuyY
My discount code SpendXBuyY - "Spend £20.00, Get 1 item free"
Other discounts works fine.

Accepted Solution (1)

hassain
Shopify Staff (Retired)
624 104 189

This is an accepted solution.

Hi @AndriiMeretskyi ,

 

The Buy X Get Y discount type with the set minimum purchase amount feature is only accessible via the GraphQL Admin API that is versioned for release 2020-01. Hope that helps.

 

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 3 (3)

hassain
Shopify Staff (Retired)
624 104 189

This is an accepted solution.

Hi @AndriiMeretskyi ,

 

The Buy X Get Y discount type with the set minimum purchase amount feature is only accessible via the GraphQL Admin API that is versioned for release 2020-01. Hope that helps.

 

To learn more visit the Shopify Help Center or the Community Blog.

Enea
Shopify Partner
19 0 2

Hi,

 

The REST API returns an ID for a discount code when you hit the discount codes API at 

 

/admin/api/2020-04/price_rules/#{price_rule_id}/discount_codes.json

Like so: 

{
  "discount_codes": [
    {
      "id": 507328175,
      "price_rule_id": 507328175,
      "code": "SUMMERSALE10OFF",
      "usage_count": 0,
      "created_at": "2020-04-06T10:20:16-04:00",
      "updated_at": "2020-04-06T10:20:16-04:00"
    }
  ]
}

What is the equivalent when using GraphQL? It seems in GraphQL API there is no id for discount codes that belong to a price rule. Am I missing something or is this no longer something we can access?

 

hassain
Shopify Staff (Retired)
624 104 189

Hi @Enea ,

 

You could achieve the same query in GraphQL like this:

{
  priceRule(id: "gid://shopify/PriceRule/298501144598") {
    discountCodes(first:50) {
      edges {
        node {
          id
          code
          usageCount
        }
      }
    }
  }
}

However with the GraphQL API you can bypass PriceRules altogether and just query for the discount codes directly: https://shopify.dev/tutorials/create-and-manage-discounts-with-admin-api . So you can just directly get the discount codes without worrying about the price rules:

 

{
  codeDiscountNodes (first:10) {
    edges {
      node {
        id
        codeDiscount {
          __typename
        }
      }
    }
  }
}

 

 

To learn more visit the Shopify Help Center or the Community Blog.