ThingSpeak

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Bulk-Update a Channel Feed

You can use the bulk-update API in certain scenarios when you want to conserve your device power. When using the bulk-update API, you can collect data over a period of time and then upload the data to ThingSpeak™. Bulk-update API takes JSON or CSV encoded data and updates the channel.

Note

If you use the React App with the Test Frequency set to On Data Insertion, the React is triggered only once per bulk update request when the Condition Type matches the Condition, even if the Condition is matched more than once.

If you set React to run on a specific Test Frequency with a specific Condition Type, be cautious of how the React is triggered. The data is now collected over a period and updated as a batch, and the Condition Type that triggers the React can vary within a single batch of data.

JSON

TitleHTTP POST Request to Bulk-Update a Channel Feed Using a JSON Object
URLhttps://api.thingspeak.com/channels/CHANNEL_ID/bulk_update.json
HTTP MethodPOST
HTTP HeaderContent-Type: application/json
Data Parameters{"write_api_key":"WRITE_API_KEY","updates":[{"created_at":"DATETIME_STAMP","field1":"FIELD1_VALUE","field2":"FIELD2_VALUE","field3":"FIELD3_VALUE","field4":"FIELD4_VALUE","field5":"FIELD5_VALUE","field6":"FIELD6_VALUE","field7":"FIELD7_VALUE","field8":"FIELD8_VALUE"},{"created_at":"DATETIME_STAMP","field1":"FIELD1_VALUE","field2": "FIELD2_VALUE","field3":"FIELD3_VALUE","field4":"FIELD4_VALUE","field5":"FIELD5_VALUE","field6":"FIELD6_VALUE", "field7":"FIELD7_VALUE","field8":"FIELD8_VALUE"},{"created_at":"DATETIME_STAMP","field1":"FIELD1_VALUE","field2":"FIELD2_VALUE","field3":"FIELD3_VALUE","field4":"FIELD4_VALUE","field5":"FIELD5_VALUE","field6":"FIELD6_VALUE","field7":"FIELD7_VALUE","field8":"FIELD8_VALUE"}]}
Success Response202: Accepted
Error Codes

400: Bad request
401: Invalid API key or channel mismatch
413: Request too large
429: Too many requests

Sample HTTP Call

POST /channels/12/bulk_update.json HTTP/1.1
Host: api.thingspeak.com
Content-Type: application/json

{
"write_api_key":"XXXXXXXXXXXXXXXXX",
"updates":[{"created_at":"2017-01-30 10:26:21 -0500","field1":1500,"field2":150,"field3":100,"field4":100,"field5":100,"field6":100,"field7":100,"field8":100},
{"created_at":"2017-01-30 10:26:2 -0500","field1":100,"field2":150,"field3":100,"field4":100,"field5":100,"field6":100,"field7":100,"field8":100},
{"created_at":"2017-01-30 10:26:2 -0500","field1":100,"field2":150,"field3":100,"field4":100,"field5":100,"field6":100,"field7":100,"field8":100},
{"created_at":"2017-01-30 10:26:2 -0500","field1":100,"field2":150,"field3":100,"field4":100,"field5":100,"field6":100,"field7":100,"field8":100}]
}

NotesReplace CHANNEL_ID with your channel ID and WRITE_API_KEY with your channel write API key. The DATETIME_STAMP must follow ISO 8601, EPOCH, or MYSQL formats.

For devices without a real-time clock, you can use relative timestamps instead of absolute timestamps. Replace the "created_at" with "delta_t" inside the updates JSON object to use relative timestamps. Here, "delta_t" represents time in seconds passed since the last measurement was recorded. For example, updates=[{"delta_t":"0","field1":"70.5","field2":"123.4","field8":"17"},{"delta_t":"10","field1":"71.6","field2":"123.5","field8":"17"}].

A single message is of the form {"delta_t":"0","field1":"70.5","field2":"123.4","field8":"17"}. Every message must start with the "created_at" or the "delta_t" parameter and must have either the relative or absolute timestamp associated with it. The number of messages in a single bulk-update is limited to 960 messages for free users and 14,400 messages for paid users. The time interval between sequential bulk-update calls should be 15 seconds or more. The time between read requests is not limited by ThingSpeak for any users.

HTTP status response 202: Accepted indicates that the server has accepted the request to update the channel. The server updates the channel in a finite amount of time. The error codes list the reasons why a request to update the channel was rejected.

Sample POSTMAN Request

You can configure the POSTMAN to try RESTful API calls. To send an HTTP POST request to bulk-update a channel feed using JSON object, configure the POSTMAN as shown:

  • In the Headers tab set the Content-Type as application/json.

  • Set the Body of the request as a raw JSON object.

CSV

TitleHTTP POST Request to Bulk Update a Channel Feed Using CSV Formatted Data
URLhttps://api.thingspeak.com/channels/CHANNEL_ID/bulk_update
HTTP MethodPOST
HTTP HeaderContent-Type: application/x-www-form-urlencoded
Data Parameters

write_api_key = WRITE_API_KEY

time_format=absolute

updates=DATETIME_STAMP,FIELD1_VALUE,FIELD2_VALUE,FIELD3_VALUE,FIELD4_VALUE,FIELD5_VALUE,FIELD6_VALUE,FIELD7_VALUE,FIELD8_VALUE,LATITUDE,LONGITUDE,ELEVATION,STATUS | DATETIME_STAMP,FIELD1_VALUE,FIELD2_VALUE,FIELD3_VALUE,FIELD4_VALUE,FIELD5_VALUE,FIELD6_VALUE,FIELD7_VALUE,FIELD8_VALUE,LATITUDE,LONGITUDE,ELEVATION,STATUS

or

write_api_key = WRITE_API_KEY

time_format=relative

updates=SECONDS_PASSED,FIELD1_VALUE,FIELD2_VALUE,FIELD3_VALUE,FIELD4_VALUE,FIELD5_VALUE,FIELD6_VALUE,FIELD7_VALUE,FIELD8_VALUE,LATITUDE,LONGITUDE,ELEVATION,STATUS | SECONDS_PASSED,FIELD1_VALUE,FIELD2_VALUE,FIELD3_VALUE,FIELD4_VALUE,FIELD5_VALUE,FIELD6_VALUE,FIELD7_VALUE,FIELD8_VALUE,LATITUDE,LONGITUDE,ELEVATION,STATUS

Success Response202: Accepted
Error Responses

400: Bad request
401: Invalid API key or channel mismatch
413: Request too large
429: Too many requests

Sample HTTP Call

POST /channels/12/bulk_update.json HTTP/1.1
Host: api.thingspeak.com
Content-Type: application/x-www-form-urlencoded

write_api_key = XXXXXXXXXXXX&time_format=relative&updates=20%2C70.5%2C60%2C50%2C%2C%2C%2C%2C%2C%2C%2C500%2CfirstMessage%7C40%2C71.5%2C60.5%2C52%2C%2C%2C%2C%2C%2C%2C%2C400%2CsecondMessage%7C50%2C71.3%2C62.5%2C53%2C%2C%2C%2C%2C%2C%2C%2C450%2CthirdMessage

NotesReplace CHANNEL_ID with your channel ID and WRITE_API_KEY with your channel write API key. If you use the time_format=absolute parameter, then the DATETIME_STAMP must follow ISO 8601, EPOCH, or MYSQL formats. %2C and %7C represents URL Encoding characters for "," and "|" respectively.

For devices without a real-time clock, use relative timestamps instead of absolute timestamps. Set time_format=relative to use relative timestamps. Here, SECONDS_PASSED represents time in seconds passed since the last measurement was recorded. For example, updates=20,70.5,60,50,,,,,,,,500,firstMessage | 40,71.5,60.5,52,,,,,,,,400,secondMessage represents two successive messages measured 20 seconds apart.

Separate successive messages within the updates parameter by |. Order a single message within the updates parameter. For example, updates=2017-01-30 10:26:21 -0500,70.5,60,50,,,,,,,,500 updates the field 1 to 70.5, field 2 to 60 and elevation to 500.

Sample POSTMAN Request

You can configure POSTMAN to try RESTful API calls. To send an HTTP POST request to bulk-update a channel feed using a CSV formatted data, configure POSTMAN as shown:

Related Examples

More About

Was this topic helpful?