Backendless Support
 
Waiting for user's response

hitting a 3rd party API from servercode works locally but not deployed

- Worked before I updated to backendless 4*

- currently on servercode 4.3.1

- API uses HTTPS

anything else I'm missing? Any debugging suggestions?

Thanks!

Leave a Comment

Comments (8)

photo
1

Hello,

what errors do you get?

photo
1

No errors. That's the problem, nothing in the logs, either. using https module in node to make the request. I got log statements on error, end and and data event callbacks, they never even get called.

Do I have to whitelist 3rd party domains I want to hit maybe?

photo
1

Are you sure, you have declared your Promise to be resolved only after you got the response ?

ServerCode works well in the DEBUG mode, but does not when deployed to the Cloud

photo
1

If that were the case, the code would not work locally, and it does. It also worked unchanged back before the migration so it feels more like a permission or timeout issue than anything else.

photo
1

permission or timeout issue would raise an error

in case of too early promise resolving, the code will work locally but not in cloud.

Could you please show us your code ?

photo
1

function request(options, callback) {

console.log('request log', options);

const req = https.request(httpOpts, function(res){

console.log('request log', 'result', res);

let chunks = [];

res.on('data', function(chunk) {

console.log('request log', 'chunk:' , chunk);

chunks.push(chunk);

});

res.on('end', function() {

const body = Buffer.concat(chunks).toString();

console.log('request log', 'end:' , res, body);

callback(null, res, body);

});

});

req.on('error', function(e) {

console.log('request log', 'error:' , e);

callback(e, null, null);

});

if (options.body) {

req.write(JSON.stringify(options.body));

}

req.end();

}

photo
1

Gal, could you please send an email to support@backendless.com with the cURL of the query triggering this servercode and that 3rd party API request, so we could trace its execution.

Btw, there is a Backendless.Request utility class available in servercode environment which can be used to send API requests.

So, you can send the request as this

Backendless.Request.post(url, body).then(response => {

console.log(response);

})

photo
photo
1

If that were the case, the code would not work locally, and it does. It also worked unchanged back before the migration so it feels more like a permission or timeout issue than anything else.