Sunday 20 October 2019

node-fetch not returning expected message

[Solved]I'm trying to use node-fetch with IFTTT to make a post request. The request works fine and I receive my notification set with the webhook, but there is one thing that is bothering me and I haven't been able to figure out how node-fetch is handling the response.const body = { value1: currentTemperature }; fetch('https://maker.ifttt.com/trigger/temp_reading/with/key/' + key, { method: 'post', body: JSON.stringify(body), headers: { 'Content-Type': 'application/json' }, }) .then(function (res) { //res.json() res.text(); console.log(res); }) .then(function (text) { console.log(text); // returns undefined }) .catch(function (err) { console.log('node-fetch error: ', err) }); Which returnsResponse { size: 0, timeout: 0, [Symbol(Body internals)]: { body: PassThrough { _readableState: [Object], readable: true, domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, _writableState: [Object], writable: false, allowHalfOpen: true, _transformState: [Object] }, disturbed: true, error: null }, [Symbol(Response internals)]: { url: 'https://maker.ifttt.com/trigger/temp_reading/with/key/key-removed', status: 200, statusText: 'OK', headers: Headers { [Symbol(map)]: [Object] }, counter: 0 } } undefined In for example, Postman or CURL, I see the resultCongratulations! You've fired the temp_reading eventInstead, with node-fetch, it returns undefined in the node console.Why does it return undefined instead of the success message? Thanks.

Submitted October 20, 2019 at 07:59AM by hey__its__me__

No comments:

Post a Comment