javascript - How do I successfully send XML requests to eBay's API server using Google Apps Script? -
the function i'm correctly using returns message saying, "the api call "getebayofficialtime" invalid or not supported in release."
function gettime() { var site = "https://api.ebay.com/ws/api.dll"; var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?> \ <getebayofficialtimerequest xmlns=\"urn:ebay:apis:eblbasecomponents\"> \ <requestercredentials> \ <ebayauthtoken>*******</ebayauthtoken> \ </requestercredentials> \ </getebayofficialtimerequest>"; var payload = { "content-type": "text/xml", "x-ebay-api-siteid": "0", "x-ebay-api-compatibility-level": "759", "x-ebay-api-call-name": "getebayofficialtime", "xml": xml }; var options = { method:"post", payload:payload }; var response = urlfetchapp.fetch(site, options); var xml = response.getcontenttext(); }; after bit of searching, found main cause of problem incorrect headers, however, i'm not sure how else set them other implemented.
you passing in both headers , xml request's payload. headers should passed in via own field. updated code below should work you.
function gettime() { var site = 'https://api.ebay.com/ws/api.dll'; var xml = '<?xml version="1.0" encoding="utf-"?> \ <getebayofficialtimerequest xmlns="urn:ebay:apis:eblbasecomponents"> \ <requestercredentials> \ <ebayauthtoken>*********</ebayauthtoken> \ </requestercredentials> \ </getebayofficialtimerequest>'; var headers = { 'content-type': 'text/xml', 'x-ebay-api-siteid': '0', 'x-ebay-api-compatibility-level': '861', 'x-ebay-api-call-name': 'getebayofficialtime' }; var options = { method: 'post', headers: headers, payload: xml }; var response = urlfetchapp.fetch(site, options); var xml = response.getcontenttext(); };
Comments
Post a Comment