-2

I'm new to eBay's API, have been creating url string and appending it to a JS-created 'script' tag, only been calling findItem / findItemAdvanced so far and had no problems receiving and processing the response.

Problem is I tried a getSingleItem request and wada-ya-know error after error.

First Attempt:

<script>
  url='htt'+'p://open.api.ebay.com/shopping?'
          +'callname=GetSingleItem'
    +'&'+'responseencoding=XML'
    +'&'+'appid=********-2a4d-4b23-8d37-defc1bbb868f'
    +'&'+'siteid=0'
    +'&'+'version=515'
    +'&'+'ItemID=191467818411'
    +'&'+'callback=funCB'
  /******************************/
  elm=document.createElement('script')
  elm.src=url
  document.body.appendChild(elm)
</script>

Which is an exact duplicate of the method for the find call except for the url & REST-PAYLOAD:

  url='htt'+'p://svcs.ebay.com/services/search/FindingService/v1'
    +'?OPERATION-NAME=findItemsAdvanced'
    +'&SERVICE-VERSION=1.0.0'
    +'&SECURITY-APPNAME=********-2a4d-4b23-8d37-defc1bbb868f'
    +'&GLOBAL-ID=EBAY-GB'
    +'&RESPONSE-DATA-FORMAT=XML'
    +'&REST-PAYLOAD=true'

So I ask myself why, go on the hunt, find out about several different methods to make the call & finally decide that the jQuery $.ajax() GET/POST method is best suited to my limited coding capability.

After much practice I came up with a call that works for the finding but not the damn getItem url.

$(document).ready(function(){
  /******************************
  url='htt'+'p://svcs.ebay.com/services/search/FindingService/v1'
    +'?OPERATION-NAME=findItemsAdvanced'
    +'&SERVICE-VERSION=1.0.0'
    +'&SECURITY-APPNAME=********-2a4d-4b23-8d37-defc1bbb868f'
    +'&GLOBAL-ID=EBAY-GB'
    +'&RESPONSE-DATA-FORMAT=XML'
    +'&REST-PAYLOAD=true'
    +'&paginationInput.entriesPerPage=3'
    +'&keywords=charizard'
  /******************************/
  url='htt'+'p://open.api.ebay.com/shopping?'
    +'callname=GetSingleItem'
    +'&'+'responseencoding=XML'
    +'&'+'appid=********-2a4d-4b23-8d37-defc1bbb868f'
    +'&'+'siteid=0'
    +'&'+'version=515'
    +'&'+'ItemID=191467818411'
    +'&'+'IncludeSelector=Description'
  /************************************/
  var id;
  $.ajax({
    type: 'GET',
    url: url,
    dataType: 'jsonp',
    jsonp: 'callbackname',
    success: function(xml,status,request){ console.log(xml); },
    error: function(request,status,error){ alert('Status: '+status+'\n\nError: '+error); },
    complete: function(request,status){ alert('Finished & '+status); }
  });
});

I've already had to fight past the xml/jsonp barrier to get this far and now this error:

Resource interpreted as Script but transferred with MIME type text/xml

Is popping up no matter what I try to get my head around.

Cœur
  • 37,241
  • 25
  • 195
  • 267
LostInCyberSpace
  • 413
  • 4
  • 19
  • Please use regular markdown for syntax highlighting. It's only after my formatting edit that we can understand that you had an opening comment `/******************************` with a closing `/******************************/`. – Cœur Sep 19 '17 at 13:29

1 Answers1

1

You code says:

responseencoding=XML

and:

RESPONSE-DATA-FORMAT=XML

XML is not JSONP.

To process a response as JSONP, the server must format the response as JSONP.

eBay's API may or may not support JSONP, but if it does, you have to ask for that and not for XML.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • this is all new to me, but after much trial and error the only way i can get ebay to accept the ajax request is if the `dataType` is set to `jsonp`. And with regards to the `RESPONSE-DATA-FORMAT` either `XML`,`NV` or`JSON` can be used successfully, without error, when the `findItemsAdvanced` url is used in conjunction with the ajax request... – LostInCyberSpace Jan 07 '15 at 03:19