9:37 am

August 8, 2019

Hi there
I need to do a bulk upload to Thingspeak of a CSV file.
Unfortunately, I can only find code examples that use Python.
But under no circumstances will I use Python.
On my Raspberry Pi, I primarily use nodejs. I have not been able to find code examples for this.
I know you need an httpXMLrequest (POST). But how?
Best regards Poul C
2:29 pm

May 2, 2019

This works for me:
async function bulkUpdate(url, bulkJson) {
const response = await fetch(url, {
method: 'post',
body: JSON.stringify(bulkJson),
headers: {
'Content-Type': 'application/json'
},
});
console.log(response);
}
This function can be called like this:
url = 'https://api.thingspeak.com/channels/' + channel + '/bulk_update.json';
bulkUpdate(url, bulkJson);
In the above, 'channel' is your ThingSpeak channel number. 'bulkJson' is the object that contains the bulk update information:
let bulkJson = {
write_api_key: ''...your write key goes here..."
updates: []
};
Each entry in the bulkJson.updates array is something like this:
bulkJson.updates.push({
created_at: timestamp,
field1: value
})
I hope this helps. I was struggling with this for a while until I included
headers: {
'Content-Type': 'application/json'
},
as described above.
Most Users Ever Online: 166
Currently Online:
30 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:
Advantagetreeexperts, laundrydaddyuk, techhhelp5, ken, tran, huldacormierModerators: cstapels: 460
Administrators: Hans: 405, lee: 457