Get HTTP request info from a hubAction response?

Hey all,

I have a SmartApp which has to do a HTTP GET, using sendHubCommand, to get the temperature of a sensor. The REST servers returns the temperature, and only the temperature… Nothing about which device it is for.

So my issue is identifying which sensor that value is for. Is there anyway I can access the HTTP request headers from the response?

def response(evt){
    def msg = parseLanMessage(evt.description);
    // msg.request.headers??
}

Then I could then figure out what the request URL was, and determine which sensor the data is for.

Thanks,
iBeech

The response headers can be found using these, but not sure if it maintains any info from the request itself

def headersAsString = msg.header // => headers as a string
def headerMap = msg.headers // => headers as a Map

@kevintierney has you covered. Here’s the link to the documentation showing what else you get as a result of parseLanMessage:
http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-lan-connected-device-types/building-the-device-type.html#parsing-the-response

If you’re building this in a device type, isn’t the response relatively 1:1? Meaning that all the requests for that SmartThings device will be going to the same sensor device? Or does the temperature sensor endpoint have multiple device/sensor values available?

It’s running in a smart app which has multiple sensors. I knew I could get the response headers, but it’s the request headers I’m after :frowning:

1 Like

Can you provide more information on the device you are making the call to? Maybe it’s possible to load up the request in a way that the response body or response headers include some identifying information?

Sure, it’s WebIOPi and I’m calling the temperature REST command. I’ll come back and update with more info once I’m outa bed

Any progress on this?

I am calling an API which returns temperature values for multiple thermostats. Each temp has it’s own endpoint call (GET path), and each api call returns only a temperature value. So the only way I can know which temp I’ve received data for is by being able to access the GET path in parse()

I can’t find a way to do this currently.

thanks