The latest SharpTools.io release includes support for making HTTP / REST API calls from any tile that supports hyperlink actions.
Tiles that support Hyperlink action (tap to expand)
- Monthly Calendar Tile
- Weather Tile
- Hero Attribute Tile
- Clock Tile
- Date Tile
- Day of Week Tile
- Media Tile
- Variable Tiles
- String Variable Tile
- Number Variable Tile
- True/False Variable Tile
Important
The REST endpoint you are calling must be SSL encrypted. Most browsers will throw a mixed-content warning if you try to communicate with an insecure endpoint.
URL Format (Syntax)
To make an HTTP REST API call, configure your Hyperlink URL with a special syntax indicating the type of REST call you are making and optional payload (if supported).
HTTP GET :
$.get("https://your.cool.url")
HTTP POST :
$.post("https://your.cool.url", { "mantra": "This is the way"})
HTTP PUT :
$.put("https://your.cool.url", { "catchphrase": "I have spoken"})
HTTP DELETE :
$.delete("https://your.cool.url")
Run SharpTools Rule
You can run a SharpTools Rule from any tiles that support the hyperlink action using the following syntax:
$.runRule("RULEID")
You can find the Rule ID in the URL while editing your desired rule.
https://sharptools.io/rule/edit/QT9hIErhEQxISxa20mYR ↑ Rule ID
$.runRule()
Parameters
The $.runRule()
syntax also supports parameters which can be accessed as part of the HTTP Trigger context variables.
$.runRule("RULEID", {"button": 1})
Or customize the message
that you plan on including as part of a notification:
$.runRule("RULEID", {"message": "Hello World"});
Dashboard Sharing: dashboards that are shared which use the special
$.runRule()
hyperlink syntax will not share the linked rule with your guest. Options include:
- Use the native Rule Tile or Super Tile as those share the underlying rule resource
- Create and share a separate dashboard with Rule Tiles on it just to grant your guest access to your desired rules. Those rules can then be used in hyperlinks in other dashboards that are shared with your guest.
Proxy Support (IFTTT, WebCoRE)
We’ve added an optional configuration object which enables you to configure the HTTP REST API requests to proxy through SharpTools servers. This is often helpful for services like IFTTT or WebCoRE which have issues receiving requests directly from browsers. (eg. CORS configuration issues).
To use this feature, pass a configuration object as the last parameter with a ‘proxy’ key set to true:
HTTP GET
$.get("https://maker.ifttt.com/trigger/change_volume/with/key/XXXXX", {"proxy": true})
HTTP POST
$.post("https://your.cool.url", {"volume": 10}, {"proxy": true})
Headers Support
The Hyperlink REST API syntax now supports an optional configuration object which supports passing in a set of headers to include in your REST API call.
$.get(url, config)
$.post(url, data, config)
$.put(url, data, config)
$.delete(url, config)
This means you could include custom headers needed by your API:
$.post("https://mycoolapi.com/update", {}, {"headers": { "X-Species": "Ferengi"}})
Note that you’ll need to pass an empty data object {}
for the post and put calls if you don’t have any payload.
Note that these requests are made directly from your browser, so you can make requests to LAN devices, but since SharpTools is served over SSL, your local endpoints must also have a valid SSL certificate. One approach to this is to use a small webserver on a NAS or Raspberry PI to create an SSL proxy.