XML requests to eBay's API using Google Apps Script returns 'The API call "GeteBayOfficialTime" is invalid or not supported in this release' error

StackOverflow https://stackoverflow.com/questions/22310031

Pregunta

The function I'm correctly using returns a message saying, "The API call "GeteBayOfficialTime" is invalid or not supported in this 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 a bit of searching, I found that the main cause of this problem is incorrect headers, however, I'm not sure how else to set them other than what is currently implemented.

¿Fue útil?

Solución

You are passing in both the headers and xml into the request's payload. The headers should be passed in via their own field. The updated code below should work for 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();
};
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top