Sending an http post request - help with groovy

hello all, I have been successfully sending requests to my device, but i need to make my coding a little more versatile. this is what i have so far:

def post_to_dev(def dev_link, def dev_type, def dev_action) 
log.debug "sending request to device: ${dev_link} -> ${dev_type}:${dev_action}"
def params = [
    uri: "${dev_link}",
    body: ["${dev_type}" : "$dev_action"]
try {
    catch (e)
        log.debug "something went wrong: $e"

sending like this:

post_to_dev("xxxxxxxxxxxxxxxxxx" , "pin9" , "ON")

when i send pin9: ON it never goes as "ON"
my problem is at this line:

    body: ["${dev_type}" : "$dev_action"]

i need the “$dev_action” to br variable.
I have tried:

nothing works. It only works when i replace specifically

body: ["${dev_type}" : "ON"]


body: ["${dev_type}" : "OFF"]

Could someone help?

Have you tried changing body: ["${dev_type}" : “$dev_action”] to body: ["${dev_type}" : “${dev_action}”]
You may also want to add log.debug “${dev_action}” right above it to verify it has the value you expect.

thanks for the reply yes i tried it.
when i do this i receive this on the other side:


when i send a body: ["${dev_type}" : “ON”] i receive:


which is what i want.
Any other ideas?

it sound like you are getting more data than you want from $dev_action. $dev_action.values, may work or you can ensure that $dev_action just has the value of “ON” by parsing your json better further up in your code.