ThingHTTP App

ThingHTTP enables communication among devices, websites, and web services without having to implement advanced HTTP protocols, authentication, and security at the device level. You can define complex requests and use a simple HTTP POST to the ThingHTTP API, which executes the request.

ThingHTTP supports HTTP GET, POST, PUT, and DELETE methods, SSL, Basic Authentication, custom host name, custom headers, different content types, and the 1.0 and 1.1 versions of HTTP. With this app, you can have a device interface with many web services and APIs, such as Prowl and Twilio.

Create a ThingHTTP Request

  1. Click Apps › ThingHTTP.
  2. Click New ThingHTTP.
  3. Specify settings:
    • Name: Enter a unique name for your ThingHTTP request.
    • API Key: Auto generated API key for the ThingHTTP request.
    • URL: Enter the address of the website or the web service to read data from or write data to, starting with either http:// or https://.
    • HTTP Auth Username: If your URL requires authentication, enter the username for authentication to access private channels or websites.
    • HTTP Auth Password: If your URL requires authentication, enter the password for authentication to access private channels or websites.
    • Method: Select the HTTP method required to access the URL.
    • Content Type: Enter the MIME or form type of the request content. For example, application/x-www-form-urlencoded.
    • HTTP Version: Select the version of HTTP on your server.
    • Host: If your ThingHTTP request requires a host address, enter the domain name. For example, api.thingspeak.com.
    • Headers: If your ThingHTTP request requires custom headers, enter name of the header and a value.
    • Body: Enter the message you want to include in your request.
    • Parse String: If you want to parse the response, enter the exact string to look for in the response data.

Send ThingHTTP Request

Send an HTTP POST to https://api.thingspeak.com/apps/thinghttp/send_request to trigger the request. Include your ThingHTTP API key and message.

When you send the POST request to your ThingHTTP, it executes the defined HTTP request and returns the response to you.

Example

Send an HTTP POST request.

POST https://api.thingspeak.com/apps/thinghttp/send_request
     api_key=XXXXXXXXXXXXXXXX
     message=hello world

Custom Replacement Keys

A ThingHTTP request has placeholders for custom key-value pairs that you can replace with specific values. When you send the request, insert the values within the %% signs in the ThingHTTP body form field. For example:

from=thingspeak&message=%%message%%

Pass the replacement name in the API request as a parameter, without the enclosing %% signs. For example:

POST https://api.thingspeak.com/apps/thinghttp/send_request
     api_key=XXXXXXXXXXXXXXXX
     message=hello world

sends the string "hello world" as the message.

Channel Value Replacements

Include channel data in your ThingHTTP request to get the last value from a channel field:

%%channel_CHANNEL_ID_field_FIELD_NUMBER%%

For example, to set the "message" parameter equal to the last value from Channel 1417, field 1:

message=%%channel_1417_field_1%%

Parse String

ThingHTTP sends the full response generated by the request. To extract a piece of data from the response, add a parse string to the ThingHTTP request, with a Parent_cell.child_cell format. If you know the full XPATH to the data, specify the XPATH as the parse string.

Example

Use ThingHTTP to send the following request to Google Finance.

URL: https://www.google.com/finance
     Method: GET
     Parse String: #ref_626307_c 

The request parses the response for the string ref_626307_c, which corresponds to the S&P 500 current price change for the day.

Additionally, you can parse JSON data with JavaScript-equivalent dot notation.

TimeControl Replacements

The TimeControl app can trigger a ThingHTTP request. Use replacement keys to access time data from a TimeControl, relative to your time zone:

  • %%datetime%%: The full date and time, for example: 2014-09-24 5:32 p.m.
  • %%day%%: The name of the weekday, for example: Wednesday
  • %%day_index%%: The zero-based index of the weekday starting on Sunday, for example: 3
  • %%hour%%: The hour of the day, for example: 5 p.m.
  • %%minute%%: The minute of the day, for example: 32
  • %%time%%: The time of the day, for example: 5:32 p.m.

Related Links

Tutorials