GraphQL API: Query all discount codes

Solved

GraphQL API: Query all discount codes

jahilldev
Shopify Partner
26 1 10

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
26 1 10

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
26 1 10

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
        }
      }
    }
  }
}