codeDiscountNode
Returns a code discount resource by ID.
Anchor to Possible returnsPossible returns
- Anchor to DiscountCodeNodeDiscount•
Code Node The
object enables you to manage code discounts that are applied when customers enter a code at checkout. For example, you can offer discounts where customers have to enter a code to redeem an amount off discount on products, variants, or collections in a store. Or, you can offer discounts where customers have to enter a code to get free shipping. Merchants can create and share discount codes individually with customers.
Learn more about working with Shopify's discount model, including related queries, mutations, limitations, and considerations.
- Query a code discount by its ID
- Querying a non-existent code discount returns null
Examples
query {
codeDiscountNode(id: "gid://shopify/DiscountCodeNode/206265824") {
id
codeDiscount {
... on DiscountCodeBasic {
title
summary
codes(first: 1) {
nodes {
code
id
}
}
}
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "query { codeDiscountNode(id: \"gid://shopify/DiscountCodeNode/206265824\") { id codeDiscount { ... on DiscountCodeBasic { title summary codes(first: 1) { nodes { code id } } } } } }"
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query {
codeDiscountNode(id: "gid://shopify/DiscountCodeNode/206265824") {
id
codeDiscount {
... on DiscountCodeBasic {
title
summary
codes(first: 1) {
nodes {
code
id
}
}
}
}
}
}`,
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: `query {
codeDiscountNode(id: "gid://shopify/DiscountCodeNode/206265824") {
id
codeDiscount {
... on DiscountCodeBasic {
title
summary
codes(first: 1) {
nodes {
code
id
}
}
}
}
}
}`,
});
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 {
codeDiscountNode(id: "gid://shopify/DiscountCodeNode/206265824") {
id
codeDiscount {
... on DiscountCodeBasic {
title
summary
codes(first: 1) {
nodes {
code
id
}
}
}
}
}
}
QUERY
response = client.query(query: query)