javascript - 是否可以在一次调用中访问多个产品变体信息?Shopify API 节点
问题描述
我正在使用 shopify-api-node 包,该包在使用 Shopify 的 api 时非常流行。一切都很顺利,但是当尝试一次调用多个产品变体时,似乎出现了问题。调用产品变体时,它需要我在尝试调用变体之前检索到的产品 ID。当尝试一次调用多个变体上的一组 id 时,我收到一条错误消息,上面写着“(节点:4628)UnhandledPromiseRejectionWarning:HTTPError:响应代码 414(请求 URI 太大)”。我还尝试使用 .join() 用逗号分隔 id,但这样做之后它只返回第一个 id 的变体,而忽略其余的。任何帮助都会很棒!
shopify 节点包:https ://www.npmjs.com/package/shopify-api-node
shopify api 产品变体文档:https ://shopify.dev/docs/admin-api/rest/reference/products/product-variant#index-2021-04
const Shopify = require('shopify-api-node');
const shopify = new Shopify({
shopName: 'removed',
apiKey: 'for',
password: 'post'
});
async function callReq(val) {
let params = { limit: 10 };
// first do while loop is to access all of the product ids
do {
const products = await shopify.product.list(params);
var getIds = (JSON.parse(JSON.stringify(products), function(key, value) {
(key == 'id') ? idArray.push(value): null;
}));
await new Promise(resolve => setTimeout(resolve, 500));
params = products.nextPageParameters;
console.log(idArray.length)
} while (params !== undefined);
// Second do while loop is for accessing the product variants using the ids gathered prior
do{
let params = { limit:250 };
// problem is here when trying to list the product variants I'm only able to list one at a
time rather than calling multiple by separating each id with a comma as stated in shopify
api
const variants = await shopify.productVariant.list(idArray, params);
console.log(JSON.stringify(variants));
var getSkus = (JSON.parse(JSON.stringify(variants), function(key, value) {
(key == 'sku') ? value != null ? skuArray.push(value) : null : null;
(key == 'price') ? costArray.push(value): null;
}));
}
}while(params !== undefined);
}
}
解决方案
推荐阅读
- modx - 更新自己的 modx 包时清空变更日志
- javascript - 如何过滤两个数组以获取相关对象?
- javascript - 如何在跨域 iframe 中前后移动
- javascript - 如何将 Url 解析为对象
- keycloak - 应用程序无法连接到 Keycloak 策略执行器
- r - 如何用透明颜色隐藏箱线图后面的误差线?
- javascript - Anguar 组件通信的 Javascript 基础知识
- php - 更新没有数据库的 Laravel Scout (Algolia)
- qt - 是否可以在运行时更改 QML 中 ChartView 上 LineSeries 的顺序?
- android - 使用嵌套的 RecyclerViews + AppBarLayout 向多个方向滚动