我是否以正确的方式将Flipkart API的标头传递给Flipkart API?

时间:2019-05-04 09:47:32

标签: javascript https fetch-api flipkart-api

我正在使用Flipkart会员API从此API端点https://affiliate-api.flipkart.net/affiliate/offers/v1/all/json获取产品报价列表

我正在使用的API要求我像这样在标头中传递ID和令牌

Fk-Affiliate-Id       <your Affiliate Tracking ID>
Fk-Affiliate-Token  <your Affiliate API Token>

所以我已经传递了所需的ID和令牌(例如下面的代码)

但是出现以下错误

script.js:99 GET https://affiliate-api.flipkart.net/affiliate/offers/v1/all/json 401 (Unauthorized)
(anonymous) @ script.js:99
script.js:100 Uncaught (in promise) SyntaxError: Unexpected end of input
    at script.js:100

我已经在Flipkart网站上验证了API端点,并且运行良好,还使用curl curl -H "Fk-Affiliate-Id:<your Affiliate Tracking ID>" -H "Fk-Affiliate-Token:<your Affiliate API Token>" "<API URL>"测试了该端点,并使用正确的必需数据进行了响应。

let url = 'https://affiliate-api.flipkart.net/affiliate/offers/v1/all/json';

let options = {
    mode: 'no-cors',
    headers: {
        "Fk-Affiliate-Id": id,
        "Fk-Affiliate-Token": token,
        },
}

fetch(url, options)
.then(res => res.json())
.then(data => console.log(data))

0 个答案:

没有答案