Get Alert History

Get alerts history with HTTP GET

Request

HTTP Method

GET

URL

https://api.thingspeak.com/alerts/history

URL Parameters

NamePriorityDescription

count

Optional

The number of results to return. The default value is 10, the maximum value is 100.

after

OptionalInclude only history items with requested_at later than this time. Format times per ISO 8601. For example, 2020-05-15T20:03:48-05:00 represents May 15, 2020, 20:03:48 EST. If you do not include the time zone offset, ThingSpeak assumes the specified time is in UTC.

before

OptionalInclude only history items with requested_at earlier than this time. Format times per ISO 8601. For example, 2020-05-15T20:03:48-05:00 represents May 15, 2020, 20:03:48 EST. If you do not include the time zone offset, ThingSpeak assumes the specified time is in UTC.

subject_contains

OptionalInclude only history items with subject containing this value, sensitive to case.

status

OptionalInclude only history items with status containing this value.

Example: https://api.thingspeak.com/alerts/history?count=10

Headers

NamePriorityDescriptionValue Type
ThingSpeak-Alerts-API-KeyRequired

Specify the alerts API key, which you can find in your profile. This key is different from the channel API and user API keys.

string

Body Parameters

There are no available body parameters for this API call.

Response

Success

HTTP Status Code

200 OK

Error

You can use the Accept header to control the detail provided with error messages. Provide the Accept header and key application/json,application/problem+json and the server returns detailed error messages along with the standard HTTP response code.

For the full list of possible HTTP errors, see Error Codes.

Examples

collapse all

You can use MATLAB® to read your alert history. This example shows how to make an HTTP request to generate your alerts history. Note that you can write the following code in any MATLAB environment, including MATLAB Analysis and desktop MATLAB.

Set the alerts API key and the URL for the request. Your alerts API key is located at Account > My Profile.

apiKey = 'XXXXXXXXXXXXXXXX';
history_url = "https://api.thingspeak.com/alerts/history"

The alerts send request requires an API key header. Build weboptions so that webread can appropriately write your HTTP request. Also create the email body and subject.

options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", apiKey ]);

Use webread to make the get history request.

myHistoryStruct = webread(history_url, options);

The web request returns a struct. Use struct2table, datetime, and table2timetable to rewrite the output into an easier to view form.

history = struct2table(myHistoryStruct, "AsArray", true);
history.requestedAt = datetime(history.requestedAt, 'InputFormat', "uuuu-MM-dd'T'HH:mm:ss.SSSz", 'TimeZone',"America/New_York");
history = table2timetable(history)
history =

  2×3 timetable

        requestedAt                    sentAt                        subject               status 
    ____________________    ____________________________    __________________________    ________

    18-Dec-2019 13:46:48    {'2019-12-18T18:46:54.160Z'}    {'Plant soil information'}    {'sent'}
    18-Dec-2019 13:43:36    {'2019-12-18T18:43:42.032Z'}    {'Plant soil information'}    {'sent'}