I’m pretty sure this isn’t possible to do the way I’m trying, but maybe there’s a different way to do what I want, so I’ll ask anyway.
I am trying to create a custom tile using json data in Hubitat. It’s too clunky to throw the json into a device attribute, and I’m afraid I’ll hit the character limit for an attribute anyway. So I’m trying to retrieve the json data from Hubitat in a different way. I don’t see a way for me to retrieve it via Maker API, because it seems I can only retrieve device configuration info and attribute values, not device state or data returned from a command. So I tried a Hubitat cloud endpoint, but it seems as though there’s access control issues (that can’t be solved by using a proxy configuration parameter in the get call because that’s only available in first-party tiles). So that leaves me out of ideas… any other way you can think of to retrieve values from Hubitat outside of a device attribute from a custom tile?
The data I’m trying to retrieve is not sensitive. I wouldn’t really care if it was made public. But it can change, so I need to be able to dynamically fetch it.
Can you share more details about the data? Just trying to better understand why it needs to be in Hubitat? There’s a variety of different JSON ‘bins’ available online that might be a good fit for this.
I wonder if you could modify the response headers. I recall playing with this at one point when I wanted to modify the returned ‘Content-Type’ header with a proof of concept I was playing with years back. Let me search and see if I can find it…
Edit: Here’s the snippet for changing the content type. I’m away from my hub at the moment, but I wonder if a similar approach could be used for the Access-Control-Allow-Origin header:
Example Code
definition(
name: "Test HTML Endpoints",
namespace: "joshualyon",
author: "Josh Lyon",
description: "Test HTML Endpoints",
category: "Amazing Apps",
iconUrl: "",
iconX2Url: "",
oauth: [displayName: "HTML Endpoint", displayLink: "https://sharptools.io"]){
}
preferences(){
page(name: "setupScreen")
}
def setupScreen(){
if(!state.accessToken){
//enable OAuth in the app settings or this call will fail
createAccessToken()
}
def uri = getFullLocalApiServerUrl() + "/?access_token=${state.accessToken}"
return dynamicPage(name: "setupScreen", uninstall: true, install: true){
section(){
paragraph("Use the following URI to access the page: <a href='${uri}'>${uri}</a>")
}
}
}
mappings {
//the root path - you can also map other paths or use parameters in paths and posted data
path("/") { action: [ GET: "renderWebsite" ] }
}
def renderWebsite(){
log.info "Rendering page"
html = "<html><head><title>Awesome Page</title></head><body><h1>hello world</h1></body></html>"
render contentType: "text/html", data: html, status: 200
}
For others, just make the last line from Josh’s code snippet: render contentType: "application/json", data: jsonData?.toString(), status: 200, headers: ["Access-Control-Allow-Origin": "https://run.sharptools.app"]