{"id":545,"date":"2011-04-13T01:08:03","date_gmt":"2011-04-13T06:08:03","guid":{"rendered":"https:\/\/blogs.mathworks.com\/iot\/?p=545"},"modified":"2017-05-22T13:24:14","modified_gmt":"2017-05-22T17:24:14","slug":"hidden-api-commands","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/iot\/2011\/04\/13\/hidden-api-commands\/","title":{"rendered":"Hidden API Commands"},"content":{"rendered":"<p>When you are retrieving data from a ThingSpeak channel you have many options and formats to choose from. We wanted to highlight a few options that are easily overlooked.<\/p>\n<h3>Last.txt<\/h3>\n<p>Let&#8217;s say you have an Arduino and you want to get the last value in a channel. You could get your feed and then write some parsing code to extract the data that you are looking for. It&#8217;s a waste of code space and also fills your finite buffers on your microcontroller. Let the cloud do the work and give you just the value you are looking for.<\/p>\n<p>Here&#8217;s how you would get our light levels: <a title=\"The last value in a ThingSpeak Channel\" href=\"http:\/\/api.thingspeak.com\/channels\/9\/field\/1\/last.txt\" target=\"_blank\">Live Demo<\/a><\/p>\n<p>[cce]http:\/\/api.thingspeak.com\/channels\/9\/field\/1\/last.txt[\/cce]<\/p>\n<h3><strong>Modifying\u00a0the response<\/strong><\/h3>\n<p>You can even add data to the response. Maybe you have <a title=\"How to use Twilio and ThingSpeak\" href=\"https:\/\/community.thingspeak.com\/tutorials\/\/twilio\/make-calls-with-twilio-using-the-thinghttp-app\/\">Twilio<\/a> reading back your temperature. It would not be much fun if Twillio says to you, &#8220;80&#8221;. Sensor data without context is noise!<\/p>\n<p>Here are two optional parameters when returning the last data on a ThingSpeak Channel:<\/p>\n<ul>\n<li>prepend=[text to add before the API response]<\/li>\n<li>append=[text to add after the API response]<\/li>\n<\/ul>\n<p><a title=\"Using prepend and append to modify a ThingSpeak API response\" href=\"http:\/\/api.thingspeak.com\/channels\/9\/field\/1\/last.txt?prepend=Your%20light%20level%20is%20&amp;append=.%20Is%20someone%20in%20your%20room?\" target=\"_blank\">Live Demo<\/a><\/p>\n<p>[cce]http:\/\/api.thingspeak.com\/channels\/9\/field\/1\/last.txt?prepend=Your%20light%20level%20is%20&amp;append=.%20Is%20someone%20in%20your%20room?[\/cce]<\/p>\n<p>Check out the <a title=\"ThingSpeak Documentation\" href=\"https:\/\/www.mathworks.com\/help\/thingspeak\/channels-and-charts-api.html\">ThingSpeak Documentation<\/a> for more information.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you are retrieving data from a ThingSpeak channel you have many options and formats to choose from. We wanted to highlight a few options that are easily overlooked.<br \/>\nLast.txt<br \/>\nLet&#8217;s say you&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/iot\/2011\/04\/13\/hidden-api-commands\/\">read more >><\/a><\/p>\n","protected":false},"author":148,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[30,62,61],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/545"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/users\/148"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/comments?post=545"}],"version-history":[{"count":13,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/545\/revisions"}],"predecessor-version":[{"id":2124,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/545\/revisions\/2124"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media?parent=545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/categories?post=545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/tags?post=545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}