Fetching data from thingspeak | ThingSpeak Projects | Forum

The ThingSpeak community site has been upgraded to a new site. This site is currently in read-only mode. You can ask questions or post and read discussions on the new site.

Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Fetching data from thingspeak
No permission to create posts
March 20, 2019
4:52 am
New Member
Forum Posts: 1
Member Since:
March 8, 2019
sp_UserOfflineSmall Offline

I am trying to fetch data from thingspeak using nodejs. This is my code

https.get('https://api.thingspeak.com/channels/XXXXXX/fields/1/last.json?key=XXXXXXXXXXXXXXX', function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
context.done(null, 'FAILURE');

The output that i get is
ClientRequest {
[Object: null prototype] {
response: { [Function: bound onceWrapper] listener: [Function] },
{ [Function: bound onceWrapper] listener: [Function: onSocket] },
error: [Function] },
_eventsCount: 3,
_maxListeners: undefined,
[ 'GET /channels/XXXXX/fields/1/last.json?key=XXXXXXXXXXXX HTTP/1.1
Host: api.thingspeak.com
Connection: close

' ],
outputEncodings: [ 'latin1' ],
outputCallbacks: [ [Function: bound onFinish] ],
outputSize: 118,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: null,
connection: null,
'GET /channels/XXXXXX/fields/1/last.json?key=XXXXXXXXXXXX HTTP/1.1
Host: api.thingspeak.com
Connection: close

_onPendingData: [Function: noopPendingOutput],
Agent {
_events: [Object: null prototype] { free: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: { path: null },
requests: {},
sockets: { 'api.thingspeak.com:443::::::::::::::::': [Array] },
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: { map: {}, list: [] } },
socketPath: undefined,
timeout: undefined,
method: 'GET',
path: '/channels/XXXXX/fields/1/last.json?key=XXXXXXXXXXX',
_ended: false,
res: null,
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
[Symbol(isCorked)]: false,
[Object: null prototype] { host: [ 'Host', 'api.thingspeak.com' ] } }
Got response: 200

I don't get the field value.I believe what I am getting is the http header. How can i get the actual data.
The output that i am expecting is


How is it possible to rectify this error?

When I use the url in the browser to fetch data, i receive the apt response. The output doesn't come when fetched through the code.

March 22, 2019
9:47 am

Forum Posts: 885
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

There is a node.js client here

Its not terribly recent, but perhaps it could help.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
17 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Zain-Ul-Abidin, wellbeingcentresuk, Vamsi, frankmehlhop, bhumin, dennysrodialah

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457