eBay Average Selling Price

फ्रीमियम
द्वारा ecommet | अपडेट किया गया 2 месяца назад | eCommerce
लोकप्रियता

9.6 / 10

लेटेंसी

2,089ms

सेवा का स्तर

100%

Health Check

N/A

सभी चर्चाओं पर वापस जाएं

400 Error Using Javascript (Fetch)

Rapid account: Philnind 17
philnind17
10 месяцев назад

I’m getting a 400 error consistently when I try to use this API through JS (Fetch)

Here is my code…

Have replaced API key with ‘XXX’ but I am 1000% sure this part is correct…

async function fetchData() {

const options = {
method: ‘POST’,
headers: {
‘content-type’: ‘application/json’,
‘X-RapidAPI-Key’: 'XXX,
‘X-RapidAPI-Host’: ‘ebay-average-selling-price.p.rapidapi.com
},
body: {
keywords: ‘iPhone’,
excluded_keywords: ‘locked cracked case box read LCD’,
max_search_results: ‘240’,
category_id: ‘9355’,
remove_outliers: true,
site_id: ‘0’,
aspects: [
{
name: ‘Model’,
value: ‘Apple iPhone X’
},
{
name: ‘LH_ItemCondition’,
value: ‘3000’
},
{
name: ‘Network’,
value: ‘Unlocked’
},
{
name: ‘Storage Capacity’,
value: ‘64 GB’
}
]
}
};

const res = await fetch(‘https://ebay-average-selling-price.p.rapidapi.com/findCompletedItems’, options)
const record = await res.json()

console.log (‘record’, record)

}

fetchData();

Rapid account: Ecommet
ecommet Commented 10 месяцев назад

In Javascript, Fetch expects the request body to be in string format.

Rapid account: Ecommet
ecommet Commented 10 месяцев назад

Found the issue. When you’re sending body data through native fetch, you need to stringify the body data. Here is updated code that I tested and works:

const KEY = ‘XXX’;

var bodyData = JSON.stringify({
“keywords”: “iPhone”,
“excluded_keywords”: “locked cracked case box read LCD face”,
“max_search_results”: “240”,
“category_id”: “9355”,
“max_pages”: “1”,
“remove_outliers”: true,
“aspects”: [
{
“name”: “Model”,
“value”: “Apple iPhone X”
},
{
“name”: “LH_ItemCondition”,
“value”: “3000”
},
{
“name”: “Network”,
“value”: “Unlocked”
},
{
“name”: “Storage Capacity”,
“value”: “64 GB”
}
]
});

const headers = {
“Content-Type”: “application/json”,
“X-RapidAPI-Host”: “ebay-average-selling-price.p.rapidapi.com”,
“X-RapidAPI-Key”: KEY

}

var requestOptions = {
method: ‘POST’,
body: bodyData,
headers: headers
};

fetch(“https://ebay-average-selling-price.p.rapidapi.com/findCompletedItems”, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log(‘error’, error));

Rapid account: Ecommet
ecommet Commented 10 месяцев назад

I’ll look into this and get back to you by the end of the day.

चर्चा में शामिल हों - नीचे टिप्पणी जोड़ें:

नई टिप्पणियाँ पोस्ट करने के लिए लॉग इन / साइनअप करें