Method to give an XML response

When collecting a Get or Post, performing an action, then responding with a success or failure…the unit that calls this smart app from the outside world expects some XML in return that looks like this:

<?xml version="1.0"?>
<vxml version="2.0">
  <var expr="0" name="__ERR_CODE__"/>
  <var expr="''" name="__ERR_DETAILS__"/>
</vxml>

How do I set up a response like that in a smartthings app? I’ve got everything else working.
Any clues? sample code, or even a link I missed in the smartthings docs.

I did create intermediate web server that collects the GET or POST, does a GET to the smartthings server to perform the function, and when it comes back to the web server, responds to the calling unit with the XML. That works perfectly. I’d like to cut out that middle “translation” server and just reply back with “that” xml. (right now I get JSON)

The app code is pretty simple:

preferences {
    section(title: "Select Devices") {
        input "light", "capability.switch", title: "Select a light or outlet", required: true, multiple:false
    }
}

mappings {
    path("/switch/on") {
        action: [
            GET: "setSwitchON"
        ]
    }
    path("/switch/off") {
        action: [
            GET: "setSwitchOFF"
        ]
    }

def setSwitchON() {
    light.on()
    return light.currentState("switch")
}

def setSwitchOFF() {
    light.off()
    return light.currentState("switch")

} 

Thanks for any clues you can give!

You can use render() to return a response that sets the contentType to specify XML content and then pass the data as the XML.

http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/smartapp.html#response-handling

2 Likes

Thank’s Jim…That’s exactly what I needed. I’ll give it a try!