我正在尝试根据https://help.shopify.com/en/api/reference/access/storefrontaccesstoken#create上发布的文档创建一个店面访问令牌。
我已经通过Admin API成功获取了访问令牌,然后尝试对/admin/storefront_access_tokens.json
进行POST调用。看来这应该很简单,但是我遇到一个错误,找不到任何相关的帖子或博客帖子。
错误:StatusCodeError:400-{“错误”:{“ storefront_access_token”:“必需参数缺失或无效”}}
我意识到我需要更改传递给函数的参数,但是我不知道“ chunk”是哪个参数。我所做的所有研究都涉及流API,但这并不是发送语音或视频数据。根据文档,响应应该只是JSON负载。
注意:我确实将商店设置为“销售渠道”,并授予该商店未经授权的访问权限
API Key: b6dfcb561d973c5d21bc59f9f5d365bd
Shop Name: qualitas-dev01.myshopify.com
有人有创建店面访问令牌的简单代码示例吗?
const shop = req.query.shop;
if (shop) {
/*#################### START CALL TO DESIRED FUNCTION #################### */
const accessToken = "f24c1215650febf0992a49f582930d7a";
const storefrontTokenRequestUrl = "https://" + shop + "/admin/storefront_access_tokens.json";
const shopRequestHeaders = {
'X-Shopify-Access-Token': accessToken,
};
console.log("QT/shopify/callback :: shopRequestHeaders <" + JSON.stringify(shopRequestHeaders) + ">");
const storefrontTokenPayload = {
"storefront_access_token": {
"title": "Test"
}
};
console.log("QT/shopify/callback :: storefrontTokenPayload <" + JSON.stringify(storefrontTokenPayload) + ">");
request.post(storefrontTokenRequestUrl, {
json: JSON.stringify(storefrontTokenPayload),
headers: shopRequestHeaders
})
.then((storefrontResponse) => {
console.log("QT :: storefrontResponse.access_token <" + storefrontResponse.access_token + ">");
console.log("QT :: storefrontResponse.access_scope <" + storefrontResponse.access_scope + ">");
console.log("QT :: storefrontResponse.created_at <" + storefrontResponse.created_at + ">");
console.log("QT :: storefrontResponse.title <" + storefrontResponse.title + ">");
res.end(storefrontResponse);
})
.catch((error) => {
console.log("QT :: ERROR in Promise!!! " + error);
//DEL: res.status(error.statusCode).send(error.error_description);
if (error.statusCode >= 100 && error.statusCode < 600) {
res.status(error.statusCode);
} else {
res.status(500);
}
res.end("Something BAD happened!!!\n" + error);
});
/*#################### END CALL TO DESIRED FUNCTION ####################*/
} else {
res.status(400).send('Missing \'shop\' parameter');
}