productById
نظرة عامة
اجلب منتجاً واحداً بواسطة ID الفريد الخاص به.
- النوع: GraphQL Query
- Endpoint: https://subdomain.com
- المصادقة:
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
}
}
}
}
المتغيرات
{
"findProductByIdId": "<PRODUCT_ID>"
}
أمثلة
- 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();
ملاحظات
- استبدل
<TOKEN>و<PRODUCT_ID>بقيم صالحة. - أضف/احذف الحقول داخل
dataلتتوافق مع احتياجات واجهتك؛ الـ query الكامل أعلاه يُظهر معظم الحقول المتاحة.