productById
Overview
Fetch a single product by its unique ID.
- Type: GraphQL Query
- Endpoint: https://subdomain.com
- Authentication:
Authorization: Bearer <TOKEN>
Query
query FindProductById($findProductByIdId: ID!) {
findProductById(id: $findProductByIdId) {
success
message
data {
_id
title
slug
description
app
tags
status
publishedAt
images { _id fileUrl }
collections {
_id
app
title
slug
description
operation
image { _id fileUrl }
}
seo { title description keywords image canonicalUrl }
pricing { compareAtPrice originalPrice price }
variantsCount
dimensions { height width unit }
weight { weight unit }
variants {
_id
product
options {
_id
option { name }
label
type
sortOrder
createdAt
updatedAt
}
images { _id fileUrl }
pricing { originalPrice price compareAtPrice }
quantity
weight { unit weight }
}
options {
_id
product
valuesCount
values { _id label type sortOrder createdAt updatedAt }
name
createdAt
updatedAt
}
}
}
}
Variables
{
"findProductByIdId": "<PRODUCT_ID>"
}
Examples
- cURL
- JavaScript (fetch)
curl -X POST \
https://subdomain.com\
-H "Content-Type: application/json" \
-H "Authorization: Bearer <TOKEN>" \
--data-binary @- << 'EOF'
{
"query": "query FindProductById($findProductByIdId: ID!) { findProductById(id: $findProductByIdId) { success message data { _id title slug } } }",
"variables": { "findProductByIdId": "<PRODUCT_ID>" }
}
EOF
const res = await fetch('https://subdomain.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
body: JSON.stringify({
query: `
query FindProductById($findProductByIdId: ID!) {
findProductById(id: $findProductByIdId) {
success
message
data { _id title slug }
}
}
`,
variables: { findProductByIdId: '<PRODUCT_ID>' },
}),
});
const json = await res.json();
Notes
- Replace
<TOKEN>and<PRODUCT_ID>with valid values. - Add/remove fields inside
datato match UI needs; the full query above shows most available fields.