Rohit
Rohit

Reputation: 3047

eBay API call in Node.js returns 'Input transfer has been terminated because your request timed out'

I want to get SessionId using eBay API. I am using Node.js as back-end. In the response I am getting this error:

Input transfer has been terminated because your request timed out.

To get sessionId I am using following approach.

var xml = '<?xml version="1.0" encoding="utf-8"?>'+
'<GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">'+
 '<RuName>MyRuname</RuName>'+
'</GetSessionIDRequest>';

var options = {
host: "api.sandbox.ebay.com",
path: '/ws/api.dll',
method: "POST",
body: xml,
headers: {
    'X-EBAY-API-APP-NAME': 'my app id',
    'X-EBAY-API-DEV-NAME': 'my dev id',
    'X-EBAY-API-CERT-NAME': 'my cert id',
    'X-EBAY-API-COMPATIBILITY-LEVEL': '557',
    'X-EBAY-API-CALL-NAME': 'GetSessionID',
    'X-EBAY-API-SITEID':'203',
    'Content-Type' : 'text/xml',
    'Content-Length':xml.length
}
};

var req = https.request(options, function (res) {
  console.log("statusCode: ", res.statusCode);
  console.log("headers: ", res.headers);

   res.on('data', function (d) {
     process.stdout.write(d);

  });

});

req.end();

req.on('error', function (e) {
   console.error('error=======', e);
});

Upvotes: 2

Views: 871

Answers (1)

user2066189
user2066189

Reputation:

The error can occur if you send an empty POST body. If you look at the nodejs docs you will see that there is no body option when creating the request object with https.request.

The correct way of setting the body in the request is to call the req.write method before calling req.end

var options = {
    host: "api.sandbox.ebay.com",
    path: '/ws/api.dll',
    method: "POST",
    headers: {
        'X-EBAY-API-APP-NAME': 'my app id',
        'X-EBAY-API-DEV-NAME': 'my dev id',
        'X-EBAY-API-CERT-NAME': 'my cert id',
        'X-EBAY-API-COMPATIBILITY-LEVEL': '557',
        'X-EBAY-API-CALL-NAME': 'GetSessionID',
        'X-EBAY-API-SITEID':'203',
        'Content-Type' : 'text/xml',
        'Content-Length':xml.length
    }
};

var req = https.request(options, function (res) {
    console.log("statusCode: ", res.statusCode);
    console.log("headers: ", res.headers);

    res.on('data', function (d) {
        process.stdout.write(d);
    });
});

req.on('error', function (e) {
    console.error('error=======', e);
});

req.write(xml);

req.end();

Upvotes: 2

Related Questions