Thank you for your assistance.
https://shopify.dev/changelog/segmentation-api-available-in-2022-04-release
I have a segmentation API scheduled for release 2022-04.
Is it currently possible to use Node.js or PHP?
PHP or in Node.js.
GraphQL request will return an error message.
“Field ‘segments’ doesn’t exist on type ‘QueryRoot’”
1.We test with code like this,
const getSegmentation = async (query) => {
try{
const response = await ShopifyData(query);
return response;
}catch(e){
return e;
}
};
router.get('/getgraphql',async (req,res,next) => {
const query =
`query {
segments(first: 10) {
nodes {
id
name
}
}
}`;
try{
const result = await getSegmentation(query);
res.json({result:result});
}catch(ex){
res.json({result:ex});
}
})
const ShopifyData = (query) => {
const URL = `https://${domain}/api/2022-07/graphql.json`
const options = {
endpoint: URL,
method: "POST",
headers: {
"X-Shopify-Storefront-Access-Token": storefrontAccessToken,
"Accept": "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ query })
}
return new Promise((resolve,reject) => {
fetch(URL, options).then(response => {
resolve(response.json());
}).catch(e => {
reject(e);
});
});
}
2.The error statement returned in this case is,
{
errors: [
{
message: "Field 'segments' doesn't exist on type 'QueryRoot'",
locations: [Array],
path: [Array],
extensions: [Object]
}
]
}
3.But,No error occurs when requesting with PRODUCTS.
router.get('/getgraphql',async (req,res,next) => {
const query =
`query {
products(first: 10) {
nodes {
id
handle
}
}
}`;
try{
const result = await getSegmentation(query);
res.json({result:result});
}catch(ex){
res.json({result:ex});
}
})
4.The result of 3 is not an error
{ data: { products: { nodes: [Array] } } }
I’ve tried the same thing with Laravel, but
Exactly the same result.
Queries such as general products do not cause errors, and queries such as
segments results in an error.
I would like to get a list of the correct segments.
Does anyone know of a solution to this?