How to get the body information in a Web Service POST handler

Hello,

I’m trying to write a SmartThings web service which is invoked via a POST with a POST body. How do I read the body of the request - i.e. the POST parameters - in the function that handles the POST?

This works almost perfectly with a GET request - see below - but I’m trying to send a URL as one of the parameters and URL encoding for the GET request doesn’t seem to work - if single encoded, SmartThings refuses with 400, if double encoded, I get a single encoded version in my SmartApp and I’d rather not have to manually decode it there. Hence, the desired change to POST…

path("/test/:param1/:param2") {
    action: [GET: "testHandler"]
}

def testHandler() {
def param1 = params.param1;
def param2 = params.param2;

}

Cheers!

Figured it out, somewhat by accident. In the handler of a POST, you can use request.JSON (capitalization matters) to get the JSON body of the request.