Method to give an XML response

(I got a hair cut from Alexa) #1

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__"/>

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() {
    return light.currentState("switch")

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


Thanks for any clues you can give!

(Jim Anderson) #2

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

(I got a hair cut from Alexa) #3

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