codeDiscountNodeByCode
Requires Apps must have access scope.
Returns a code discount identified by its discount code.
Arguments
- Anchor to codecode•String!required
The case-insensitive code of the
to return.
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.
Search for a code discount by discount code
query codeDiscountNodeByCode($code: String!) {
codeDiscountNodeByCode(code: $code) {
codeDiscount {
__typename
... on DiscountCodeBasic {
codesCount {
count
}
shortSummary
}
}
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 codeDiscountNodeByCode($code: String!) { codeDiscountNodeByCode(code: $code) { codeDiscount { __typename ... on DiscountCodeBasic { codesCount { count } shortSummary } } id } }",
"variables": {
"code": "DISCOUNTAPPLICATIONSROCKS"
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query codeDiscountNodeByCode($code: String!) {
codeDiscountNodeByCode(code: $code) {
codeDiscount {
__typename
... on DiscountCodeBasic {
codesCount {
count
}
shortSummary
}
}
id
}
}`,
{
variables: {
"code": "DISCOUNTAPPLICATIONSROCKS"
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `query codeDiscountNodeByCode($code: String!) {
codeDiscountNodeByCode(code: $code) {
codeDiscount {
__typename
... on DiscountCodeBasic {
codesCount {
count
}
shortSummary
}
}
id
}
}`,
"variables": {
"code": "DISCOUNTAPPLICATIONSROCKS"
},
},
});
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 codeDiscountNodeByCode($code: String!) {
codeDiscountNodeByCode(code: $code) {
codeDiscount {
__typename
... on DiscountCodeBasic {
codesCount {
count
}
shortSummary
}
}
id
}
}
QUERY
variables = {
"code": "DISCOUNTAPPLICATIONSROCKS"
}
response = client.query(query: query, variables: variables)