productByHandle
Requires access scope.
Return a product by its handle. Use instead.
Arguments
- Anchor to handlehandle•String!required
A unique string that identifies the product. Handles are automatically generated based on the product's title, and are always lowercase. Whitespace and special characters are replaced with a hyphen:
-
. If there are multiple consecutive whitespace or special characters, then they're replaced with a single hyphen. Whitespace or special characters at the beginning are removed. If a duplicate product title is used, then the handle is auto-incremented by one. For example, if you had two products calledPotion
, then their handles would bepotion
andpotion-1
. After a product has been created, changing the product title doesn't update the handle.
Anchor to Possible returnsPossible returns
- Anchor to ProductProduct•
The
Product
object lets you manage products in a merchant’s store.Products are the goods and services that merchants offer to customers. They can include various details such as title, description, price, images, and options such as size or color. You can use product variants to create or update different versions of the same product. You can also add or update product media. Products can be organized by grouping them into a collection.
Learn more about working with Shopify's product model, including limitations and considerations.
- Retrieve a product by a handle that doesn't exist
- Retrieve product information using the product handle
- Retrieve the ID of a product with a specified handle
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 query {6 productByHandle(handle: "there is no product with a handle like this") {7 id8 title9 productType10 description11 vendor12 }13 }`,14);1516const data = await response.json();17
query {
productByHandle(handle: "there is no product with a handle like this") {
id
title
productType
description
vendor
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "query { productByHandle(handle: \"there is no product with a handle like this\") { id title productType description vendor } }"
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query {
productByHandle(handle: "there is no product with a handle like this") {
id
title
productType
description
vendor
}
}`,
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: `query {
productByHandle(handle: "there is no product with a handle like this") {
id
title
productType
description
vendor
}
}`,
});
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 {
productByHandle(handle: "there is no product with a handle like this") {
id
title
productType
description
vendor
}
}
QUERY
response = client.query(query: query)
Response
JSON1{2 "productByHandle": null3}