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

문제

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.

도움이 되었습니까?

해결책

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();
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top