Ebay Api Cors Request Using Javascript Returns Undefined
I want to fetch JSON data from eBay Sandbox using JavaScript I tried getting it through CORS request (as it is a cross domain request) but it returns undefined. I tried lots of dif
Solution 1:
You can send a GET request to the URL.
const http = require('http');
let url = 'http://svcs.sandbox.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=NiraliAc-FlashSal-SBX-7d56b4536-d82a9262&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&keywords=harry%20potter&paginationInput.entriesPerPage=3&itemFilter(0).name=MaxPrice&itemFilter(0).value=25&itemFilter(0).paramName=Currency&itemFilter(0).paramValue=USD&itemFilter(1).name=FreeShippingOnly&itemFilter(1).value=true&itemFilter(2).name=ListingType&itemFilter(2).value(0)=AuctionWithBIN&itemFilter(2).value(1)=FixedPrice&itemFilter(2).value(2)=StoreInventory';
http.get(url, res => {
let body = '';
res.on('data', data => body += data);
res.on('end', () => {
console.log(body);
});
});
Solution 2:
I found a solution by making a CORS request and using the CORS Anywhere API from https://github.com/Rob--W/cors-anywhere/
var cors_api_url = 'https://cors-anywhere.herokuapp.com/';
functiondoCORSRequest(options, printResult) {
var x = newXMLHttpRequest();
x.open(options.method, cors_api_url + options.url);
x.onload = x.onerror = function() {
printResult(
options.method + ' ' + options.url + '\n' +
x.status + ' ' + x.statusText + '\n\n' +
(x.responseText || '')
);
};
x.send(options.data);
}
(function() {
var outputField = document.getElementById('output');
new1();
functionnew1() {
// e.preventDefault();doCORSRequest({
method: 'GET',
url: url,
}, functionprintResult(result) {
//result contains the response//write your code here
});
};
})();
Source: https://github.com/Rob--W/cors-anywhere/blob/master/demo.html
(Live example: https://robwu.nl/cors-anywhere.html)
Post a Comment for "Ebay Api Cors Request Using Javascript Returns Undefined"