Http Get request

(Jim) #1

I not a programmer but sometimes I play one at work.

Can someone tell me how to properly format an http get request in a smart app? I just need to hit a url. I think I knew at some point but I am a struggling and can’t get anything to work.

(Brian) #2

Great info here:

(Brian) #3

And for some more detail (maybe too much), I went to my Honeywell Thermostat device type and copied this for your enjoyment:

    def params = [
        uri: "${settings.honeywelldevice}",
        headers: [
              'Accept': '*/*',
              'DNT': '1',
              'Accept-Encoding': 'plain',
              'Cache-Control': 'max-age=0',
              'Accept-Language': 'en-US,en,q=0.8',
              'Connection': 'keep-alive',
              'Host': '',
              'Referer': '',
              'X-Requested-With': 'XMLHttpRequest',
              'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36',
              'Cookie': data.cookiess        ],

        httpGet(params) { response ->
        log.debug "Request was successful, $response.status"
         response.headers.each {
           log.debug "${} : ${it.value}"

//		log.trace("Response ${}")        //don't run if there are alerts, too much data
        def curTemp =

(Jim) #4

I recind my comments based on additional post …

(Ben Lebson) #5

It depends if you have a local or external IP that you’re trying to go to. If its an external IP or website then you use the httpGet command. If it’s a local IP you use hubAction in order to pass the commands.

(Jim) #6

Right - I got that - Is the syntax of using either That I think I’m lost with…

If internal url - can I just do

def result = new physicalgraph.device.HubAction(
method: “GET”,
path: “/(path)”,
headers: [
‘HOST’: “ip:port”,
log.trace result


(Ben Lebson) #7

For hubAction you need to set your device network ID to the IP:Port in hex and then you need to return hubAction within the function that calls the function that contains it (confusing, I know). Check my DCS-930L devicetype for an example:

(Mark) #8

Hi All,

I really need some help.

I need to know how to create a “Http Get” command for this url “

If this can be done we can control any of the following devices using Amazon Echo within a second.

Set Top boxes
Blu ray players
Apple TV
the list go on.

I have it working with IFTTT however it takes up to 10 seconds to change the television channel or Sky.



(Justin Wurth) #9

Here is an example of working code:

def checkStatus(){

httpGet(uri: "${deviceId}/checkStatus1?access_token=${token}",
	contentType: 'application/json',)
{resp ->           
        log.debug "resp data: ${}"
        log.debug "result: ${}"
	sendEvent(name: "switch", value: "${}" )


My json that returned was formatted with data as the main header and then result as the body.


I don’t think you can use httpGet for local network calls. You have to use hubAction instead. From what I read it’s because httpGet executes from the cloud while hubAction executes from the hub.

(Justin Wurth) #11

Yeah I was responding to @mrbloke2016. He was asking about an external call. You are correct hubAction is required for LAN based requests.

( I hate Mondays) #12

CoRE does that internally - if you make a web request and provide a local IP, it will use the proper way to reach it. Look into CoRE’s source, around line 7600.

Code excerpt:

        try {
            sendHubCommand(new physicalgraph.device.HubAction(
                method: method,
                path: (uri.indexOf("/") > 0) ? uri.substring(uri.indexOf("/")) : "",
                headers: [
                    HOST: (uri.indexOf("/") > 0) ? uri.substring(0, uri.indexOf("/")) : uri,
                query: data ?: null
        } catch (all) {
            debug "Error executing internal web request: $all", null, "error"

Simplified (without variables), it should look like:

        try {
            sendHubCommand(new physicalgraph.device.HubAction(
                method: "GET",
                path: "/enado/api/core/Triggers/13",
                headers: [
                    HOST: "",
                query: "auth_token=4fa28c87e845c996efa2819108444fd0"
        } catch (all) {
            debug "Error executing internal web request: $all", null, "error"

Try with and without the :80 in the host, see what works. Also, you may try to move the query into the path with a ? if that doesn’t work, but it should. Good luck.

(JBrown) #13

Your the Master, you helped me again. I bow to you.

(Federico Echeverria) #15

Hello, i have a Raspberry PI 3 local ip and i want to be able to run a script i have at when my samsung motion detector is active. My motion detector is integrated in my ST Hub. Can you help me out please? Thanks


I know this is an old post, but I’m trying to do something similar.

I have the above compiling when I save the code, and I’m able to publish it to my apps. I can then go into the smartthings app on my phone, and pull it down, but I can’t figure out how to trigger the smartapp. What am I missing?