Main Content

Results for

I have been having problems sending ThingSpeak alerts so I created a simple routine that demonstrates the problem. The code executes successfully but I never receive an email with the alert. What am I doing wrong?
% Set Thingspeak address, alerts API key, and options for the HTTTP call
alertUrl = "https://api.thingspeak.com/alerts/send";
alertApiKey = "TAKxxxxxxxxxxxxxxxx";
options = weboptions("HeaderFields",["ThingSpeak-Alerts-API-Key",alertApiKey]);
% Set content for email subject and body.
alertSubject = "ThingSpeak Alert Subject";
alertBody = "ThingSpeak Alert Body";
% Catch errors so the MATLAB code does not disable a TimeControl if it fails
try
webwrite(alertUrl, "body", alertBody, "subject", alertSubject, options);
catch Exception
fprintf("Failed to send alert: %s\n", Exception.message);
end