--- title: discountCodesCount - GraphQL Admin description: >- The total number of discount codes for the shop. Limited to a maximum of 10000 by default. api_version: 2025-07 api_name: admin type: query api_type: graphql source_url: html: >- https://shopify.dev/docs/api/admin-graphql/2025-07/queries/discountCodesCount md: >- https://shopify.dev/docs/api/admin-graphql/2025-07/queries/discountCodesCount.md --- # discount​Codes​Count query Requires `read_discounts` access scope. The total number of discount codes for the shop. Limited to a maximum of 10000 by default. ## Arguments * limit [Int](https://shopify.dev/docs/api/admin-graphql/2025-07/scalars/Int) Default:10000 The upper bound on count value before returning a result. Use `null` to have no limit. * query [String](https://shopify.dev/docs/api/admin-graphql/2025-07/scalars/String) A filter made up of terms, connectives, modifiers, and comparators. You can apply one or more filters to a query. Learn more about [Shopify API search syntax](https://shopify.dev/api/usage/search-syntax). * * default string * id id * times\_used integer - Filter by a case-insensitive search of multiple fields in a document. - Example: * `query=Bob Norman` * `query=title:green hoodie` Filter by `id` range. - Example: * `id:1234` * `id:>=1234` * `id:<=1234` *** ## Possible returns * Count [Count](https://shopify.dev/docs/api/admin-graphql/2025-07/objects/Count) Details for count of elements. *** ## Examples * ### Retrieve the number of discount codes used more than once #### Description Returns the number of discount codes that were used more than once. #### Query ```graphql query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } } ``` #### Variables ```json { "query": "times_used:>1" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-07/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }", "variables": { "query": "times_used:>1" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }`, { variables: { "query": "times_used:>1" }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } } QUERY variables = { "query": "times_used:>1" } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }`, "variables": { "query": "times_used:>1" }, }, }); ``` #### Response ```json { "discountCodesCount": { "count": 3 } } ``` * ### Retrieve the number of discount codes used within a range #### Description Returns the number of discount codes that were used more than onceand less than four times. #### Query ```graphql query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } } ``` #### Variables ```json { "query": "times_used:>1 AND times_used:<4" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-07/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }", "variables": { "query": "times_used:>1 AND times_used:<4" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }`, { variables: { "query": "times_used:>1 AND times_used:<4" }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } } QUERY variables = { "query": "times_used:>1 AND times_used:<4" } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }`, "variables": { "query": "times_used:>1 AND times_used:<4" }, }, }); ``` #### Response ```json { "discountCodesCount": { "count": 2 } } ``` * ### Retrieve the number of unused discount codes #### Description Returns the number of discount codes that were never used. #### Query ```graphql query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } } ``` #### Variables ```json { "query": "times_used:0" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-07/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }", "variables": { "query": "times_used:0" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }`, { variables: { "query": "times_used:0" }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } } QUERY variables = { "query": "times_used:0" } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }`, "variables": { "query": "times_used:0" }, }, }); ``` #### Response ```json { "discountCodesCount": { "count": 25 } } ``` * ### Retrieve the total number of discount codes #### Description Returns the total number of discount codes. #### Query ```graphql query discountCodesCount { discountCodesCount { count } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-07/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query discountCodesCount { discountCodesCount { count } }" }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query discountCodesCount { discountCodesCount { count } }`, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query discountCodesCount { discountCodesCount { count } } QUERY response = client.query(query: query) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query discountCodesCount { discountCodesCount { count } }`, }); ``` #### Response ```json { "discountCodesCount": { "count": 29 } } ``` * ### Retrieves a count of discount codes for a shop #### Query ```graphql query DiscountRedeemCodeCount { discountCodesCount { count } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-07/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query DiscountRedeemCodeCount { discountCodesCount { count } }" }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query DiscountRedeemCodeCount { discountCodesCount { count } }`, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query DiscountRedeemCodeCount { discountCodesCount { count } } QUERY response = client.query(query: query) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query DiscountRedeemCodeCount { discountCodesCount { count } }`, }); ``` #### Response ```json { "discountCodesCount": { "count": 29 } } ``` [Open in GraphiQL](http://localhost:3457/graphiql?query=query%20discountCodesCount\(%24query%3A%20String!\)%20%7B%0A%20%20discountCodesCount\(query%3A%20%24query\)%20%7B%0A%20%20%20%20count%0A%20%20%7D%0A%7D\&variables=%7B%0A%20%20%22query%22%3A%20%22times_used%3A%3E1%22%0A%7D) ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }`, { variables: { "query": "times_used:>1" }, }, ); const json = await response.json(); return json.data; } ``` ##### GQL ``` query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } } ``` ##### cURL ``` curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-07/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }", "variables": { "query": "times_used:>1" } }' ``` ##### React Router ``` import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }`, { variables: { "query": "times_used:>1" }, }, ); const json = await response.json(); return json.data; } ``` ##### Node.js ``` const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } }`, "variables": { "query": "times_used:>1" }, }, }); ``` ##### Ruby ``` session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query discountCodesCount($query: String!) { discountCodesCount(query: $query) { count } } QUERY variables = { "query": "times_used:>1" } response = client.query(query: query, variables: variables) ``` ## Input variables JSON ```json { "query": "times_used:>1" } ``` ## Response JSON ```json { "discountCodesCount": { "count": 3 } } ```