Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.
Solved

GraphQL API: Query all discount codes

jahilldev
Shopify Partner
16 1 0

Hi there,

 

I'm trying to query Shopify's GQL API for all discount codes created in a particular store. I'm using the Remix framework provided by Shopify for a custom app.

 

So far I have the following:

const { storefront } = await unauthenticated.storefront(shopDomain);

const response = await storefront.graphql(
  `query codeDiscountNodes {
     nodes {
        id
        codeDiscount {
        ... on DiscountCodeBasic {
          title
          summary
        }
      }
    }
  }`,
  { variables: { codeLimit } },
);

const { data } = await response.json();


This however fails with the following error message:

Error: Field 'nodes' is missing required arguments: ids


I'm obviously doing something wrong in the query, the above works fine in Shopify's GraphQL playground. 

 

To be clear, I want all discount codes for the store as I won't have any identifiers to query against. I just need a list of the first 100 or something.

 

Can someone point me towards what's wrong with the above?

 

Many thanks!

Accepted Solution (1)

jahilldev
Shopify Partner
16 1 0

This is an accepted solution.

Ack, fixed this. The query should be formatted like so:

 

query ListDiscountCodes($limit: Int!) {
  codeDiscountNodes(first: $limit) {
    nodes {
      id
      codeDiscount {
        ... on DiscountCodeBasic {
          title
          summary
        }
      }
    }
  }
}

 

View solution in original post

Reply 1 (1)

jahilldev
Shopify Partner
16 1 0

This is an accepted solution.

Ack, fixed this. The query should be formatted like so:

 

query ListDiscountCodes($limit: Int!) {
  codeDiscountNodes(first: $limit) {
    nodes {
      id
      codeDiscount {
        ... on DiscountCodeBasic {
          title
          summary
        }
      }
    }
  }
}