【问题标题】:Link Headers Missing When Trying To Paginate Products尝试对产品进行分页时缺少链接标头
【发布时间】:2022-12-23 10:58:26
【问题描述】:

我正在尝试在我的 shopify 应用程序上对产品进行分页。我遵循了本教程:https://shopify.dev/api/usage/pagination-rest#make-a-paginated-request-and-iterate-through-the-pages。问题是当我请求 Shopify API 时,我没有在响应标头中获得链接。

这是我的代码:


let url = `https://${req.user.shop}/admin/api/2022-04/products.json?limit=${limit}`;  
 
let options = {
            method: 'GET',
            mode: 'no-cors',
            uri: url,
            json: true,
            headers: {
                'X-Shopify-Access-Token': req.accessToken,
                'content-type': 'application/json',
            }   
        };
 
request(options)
        .then(function (parsedBody){
            console.log(res._headers);
            console.log(parsedBody.products);
            res.status(200).json(parsedBody.products);
        }).catch(function (err) {
            console.log(err);
            res.json(err);
        })

谢谢你的时间!

【问题讨论】:

    标签: node.js pagination shopify-app shopify-api shopify-api-node


    【解决方案1】:
    const response = await fetch(`https://${session.shop}${endpoint}`,requestOptions);
       
        if (response.ok) {
          const data = response;
          console.log(response.headers.get('Link')); 
          res.status(response.status).send(data);
        } else { 
          console.log(response); 
          res.status(response.status).send(data);
        }
    

    【讨论】:

    猜你喜欢
    • 2013-01-30
    • 1970-01-01
    • 2014-05-12
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    相关资源
    最近更新 更多