product
Get a single product by ID.
Query Structure
query {
product(id: ID!) {
handle
minQuantity
maxQuantity
seoDescription
seoTitle
seoKeywords
id
combinedListing {
# See CombinedListing object for fields
}
firstAvailableVariant {
# See ProductVariant object for fields
}
hasOnlyDefaultVariant
variants {
# See ProductVariant object for fields
}
options
optionsWithValues {
# See ProductOption object for fields
}
optionsByHandle {
# See ProductOption object for fields
}
defaultOrSelectedVariant {
# See ProductVariant object for fields
}
tags
customFields {
# See CustomField object for fields
}
inPreview
isAvailable
isDirectlyBuyable
title
manufacturer {
# See Manufacturer object for fields
}
shortDescription
description
compatible {
# See Product object for fields
}
similar {
# See Product object for fields
}
related {
# See Product object for fields
}
deliverer {
# See Deliverer object for fields
}
productGroups {
# See ProductGroup object for fields
}
returnPolicyTimeLimit
rating
reviewCount
maxRating
reviews {
# See Review object for fields
}
attachments {
# See Attachment object for fields
}
reviewsAreEnabled
reviewsRequireAccount
reviewsRequirePurchase
reviewsRequireApproval
taxonomy {
# See ProductTaxonomy object for fields
}
createdAt
updatedAt
rate
inCustomersWishlist
customerHasReviewed
customerCanReview
customerHasPurchased
}
}
Arguments
Argument | Type | Description | Required | Default |
---|---|---|---|---|
id | ID! | The ID of the product to retrieve | Yes | None |
Return Type
Type: Product
Describes a product with the following fields:
Field | Type | Description |
---|---|---|
handle | String | Returns the handle. |
minQuantity | Int | Returns the minimum quantity that can be bought. |
maxQuantity | Int | Returns the maximum quantity that can be bought. |
seoDescription | String | Returns description for search engines. |
seoTitle | String | Returns title for search engines. |
seoKeywords | String | Returns keywords for search engines. |
id | Int | Returns the id. |
combinedListing | CombinedListing | Returns the combined listing object. |
firstAvailableVariant | ProductVariant | Returns the first available variant. |
hasOnlyDefaultVariant | Boolean | Returns true if product has only default variant. |
variants | [ProductVariant] | Returns the product variants. |
options | [String] | Returns the options handles. |
optionsWithValues | [ProductOption] | Returns array of product options with values. |
optionsByHandle | [ProductOption] | Returns array of product options indexed by handle. |
defaultOrSelectedVariant | ProductVariant | Returns the selected variant or the default one if none is selected. |
tags | [String] | Returns product tags. |
customFields | [CustomField] | Returns product custom fields as CustomFieldDrop objects. |
inPreview | Boolean | Returns true if product is in preview. |
isAvailable | Boolean | Returns true if product is available for purchase. |
isDirectlyBuyable | Boolean | Returns true if product can be bought without selecting any attributes. |
title | String | Returns the title. |
manufacturer | Manufacturer | Returns the manufacturer object. |
shortDescription | String | Returns the short description. |
description | String | Returns the description. |
compatible | [Product] | Returns compatible products. |
similar | [Product] | Returns similar products. |
related | [Product] | Returns related products. |
deliverer | Deliverer | Returns the deliverer object. |
productGroups | [ProductGroup] | Returns associated product groups. |
returnPolicyTimeLimit | Int | Returns the product return policy time limit in days. |
rating | Float | Returns the rating. |
reviewCount | Int | Returns the review count. |
maxRating | Int | Returns the maximum rating. |
reviews | [Review] | Returns the product reviews. |
attachments | [Attachment] | Returns the product attachments as AttachmentDrop objects. |
reviewsAreEnabled | Boolean | Returns true if reviews are enabled for this product. |
reviewsRequireAccount | Boolean | Returns true if creating a review requires an account. |
reviewsRequirePurchase | Boolean | Returns true if product must be purchased before review can be made. |
reviewsRequireApproval | Boolean | Returns true if reviews are approved before published. |
taxonomy | ProductTaxonomy | Returns the product taxonomy. |
createdAt | String | Returns the creation date. |
updatedAt | String | Returns the last updated date. |
rate | String | Returns the tax rate. |
inCustomersWishlist | String | Returns true if product is in customer’s wishlist. |
customerHasReviewed | String | Returns true if customer has reviewed the product. |
customerCanReview | String | Returns true if customer can review the product. |
customerHasPurchased | String | Returns true if customer has purchased the product. |
Examples
Basic Query
query {
product(id: 12345) {
id
title
description
isAvailable
}
}
Advanced Query
query {
product(id: 12345) {
id
title
handle
seoTitle
seoDescription
minQuantity
maxQuantity
isAvailable
isDirectlyBuyable
tags
rating
reviewCount
variants {
id
title
sku
price
available
}
manufacturer {
id
name
}
reviewsAreEnabled
reviewsRequireAccount
reviewsRequirePurchase
reviewsRequireApproval
reviews {
id
rating
title
content
createdAt
}
productGroups {
id
name
description
}
createdAt
updatedAt
}
}
Field Selection
query {
product(id: 12345) {
id
title
options
optionsWithValues {
id
name
values
}
defaultOrSelectedVariant {
id
sku
price
available
}
attachments {
id
url
title
}
}
}
cURL Example
curl -X POST https://www.mystoreurl.com/graphql/0.8.0/ \
-H "Content-Type: application/json" \
-d '{"query":"query { product(id: 12345) { id title description isAvailable } }"}'
JavaScript Example
async function fetchProduct(productId) {
const query = `
query {
product(id: ${productId}) {
id
title
description
isAvailable
}
}
`;
try {
const response = await fetch('https://www.mystoreurl.com/graphql/0.8.0/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
});
const result = await response.json();
if (result.errors) {
console.error('GraphQL errors:', result.errors);
return null;
}
return result.data.product;
} catch (error) {
console.error('Network error:', error);
return null;
}
}
// Usage example
fetchProduct(12345).then(product => {
if (product) {
console.log('Product:', product);
} else {
console.log('Failed to fetch product.');
}
});
Response Format
The response will contain a product
object with the requested fields. Example response for a basic query:
{
"data": {
"product": {
"id": 12345,
"title": "Example Product",
"description": "This is an example product description.",
"isAvailable": true
}
}
}
If the product is not found, product
will be null
.
Error Handling
Error Code | Description |
---|---|
BAD_USER_INPUT | The provided id argument is invalid or missing. |
NOT_FOUND | No product found with the specified ID. |
INTERNAL_SERVER_ERROR | An unexpected error occurred on the server. |
RATE_LIMIT_EXCEEDED | The client has exceeded the allowed number of requests. |
Clients should check for errors in the GraphQL response’s errors
array and handle accordingly.
Performance Considerations
- Limit requested fields to only those needed to reduce response size and improve performance.
- Avoid requesting deeply nested fields unless necessary.
- Use pagination on nested lists (e.g.,
variants
,reviews
) when supported to reduce payload size. - The API enforces rate limiting; clients should implement retry logic with exponential backoff.
- Responses may be cached by clients or intermediaries; consider cache headers if provided.
Authentication
This API currently does not require authentication. However, authentication requirements may be introduced in future versions. Monitor API updates for any changes to authentication requirements.
Related Types
- CombinedListing
- ProductVariant
- ProductOption
- CustomField
- Manufacturer
- Product
- Deliverer
- ProductGroup
- Review
- Attachment
- ProductTaxonomy
Notes
- The
id
argument is mandatory and must be a valid product ID. - Fields marked as optional may return
null
if data is not available. - Some fields like
reviewsRequireAccount
andcustomerHasPurchased
provide insight into review and purchase requirements and statuses. - Use the
defaultOrSelectedVariant
field to retrieve the variant that should be displayed or purchased by default. - The
isDirectlyBuyable
field indicates if the product can be purchased without selecting variant options. - The API supports rich product data including SEO fields, manufacturer info, attachments, and related products.
Last updated on