Webhook using hubitat cloud

Hi,

I am working on integration between HA and some server in AWS.
The app should get the data sent from the server in a method in the app code...

I understand that the webhook url should look something like:
http://cloud.hubitat.com/api/HUB-ID/apps/APP-ID
It's not working event from postman... what am I missing?

the flow should be:
AWS ---> Webhook to HubitatCloud ---> hub ---> app --> some method

can someone help with an example?

10x

Did you provide the access token from the app? createAccessToken() creates state.accessToken

Did you set up the mappings in your app? Those have to be there for it to handle the GET.

Like this:

mappings {
    path("/trigger") {
        action: [
        GET: "endpointHandler", POST: "endpointHandler", OPTIONS: "options"
        ]
    }
    path("/trigger/:value") {
        action: [
        GET: "endpointHandler", POST: "endpointHandler", OPTIONS: "options"
        ]
    }
}

That has to be there for it to call the method, in this case endpointHandler(). The handler gets the request and any params, and provides the response.

The URL looks like this:

https://cloud.hubitat.com/api/HUBID/apps/APPID/trigger?access_token=ACCESSTOKEN

Note that in this example, /trigger has to do with the mappings in this case, yours would differ. The access token is generated by the app,

1 Like

Had this simple app for testing. Make sure you enable "OAUTH" on the code before deploying.

Enjoy.

definition(
    name: "hubitatTest webhook",
    namespace: "hubitat",
    author: "bloodtick",
    description: "Test a external webhook",
    category: "",
    iconUrl: "",
    iconX2Url: "",
    singleInstance: false
){}

preferences {
    page name:"pageMain"
}

def installed() {
    initialize()
}

def updated() {
    initialize()
}

def initialize() {
}

def uninstalled() { 
}

mappings { 
    path("/webhook") { action: [ GET: "webhook"] }
}

def webhook() { 
    log.info "${app.getLabel()} executing 'webhook()'"
    log.info "params: $params"
    log.info "request: $request"    
    return render(contentType: "text/html", data: "webhook params:<br>$params <br><br>webhook request:<br>$request", status: 200)
}

def getLocalUri() {
    return getFullLocalApiServerUrl() + "/webhook?access_token=${state.accessToken}"
}

def getCloudUri() {
    return "${getApiServerUrl()}/${hubUID}/apps/${app.id}/webhook?access_token=${state.accessToken}"
}

def pageMain(){
    
    if(!state.accessToken){	
        createAccessToken()	
    }
    
    def localUri = getLocalUri()
    def cloudUri = getCloudUri()
    
    return dynamicPage(name: "pageMain", install: true,  uninstall: true, refreshInterval:0) {
        
        section("Webhooks") {
            paragraph("<ul><li><strong>Local</strong>: <a href='${localUri}' target='_blank' rel='noopener noreferrer'>${localUri}</a></li></ul>")
            paragraph("<ul><li><strong>Cloud</strong>: <a href='${cloudUri}' target='_blank' rel='noopener noreferrer'>${cloudUri}</a></li></ul>")
            
        }   
    }    
}
2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.