Search code examples
javascriptwebcross-domainsame-origin-policyebay-api

Can I make eBay API calls from client side with javascript or does that violate the Same-Origin Policy?


For studying I would like to create a simple website including usage of the eBay API. I am currently in the planing process and the following question came up. "Can I make eBay calls from client side? Does that not violate the Same-Origin Policy (SOP) because its a cross domain request?"

I am a real beginner in Web Development, I guess someone can answer my question fairly easy.


Solution

  • depending on what API you want to use for example the Finding API supports jsonp,

    here a example:

    // Construct the request
    // Replace MyAppID with your Production AppID
    var url = "http://svcs.ebay.com/services/search/FindingService/v1";
        url += "?OPERATION-NAME=findItemsByKeywords";
        url += "&SERVICE-VERSION=1.0.0";
        url += "&SECURITY-APPNAME=MyAppID";
        url += "&GLOBAL-ID=EBAY-US";
        url += "&RESPONSE-DATA-FORMAT=JSON";
        url += "&callback=_cb_findItemsByKeywords";
        url += "&REST-PAYLOAD";
        url += "&keywords=harry%20potter";
        url += "&paginationInput.entriesPerPage=3";
    

    make sure to set the RESPONSE-DATA-FORMAT to "JSON" and provide a js-callback function via the "callback" param