SHELL + cURL In Dialplan

Asterisk 13.7.2


exten => s,1,GotoIf($["${CHANNEL(state)}" = "Up"]?begin)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(begin),Noop(Playing announcement howdy)
exten => s,n,Playback(custom/howdyhowdyhowdy)
exten => s,n,Set(result=${SHELL(curl -s '' |     python -c "import sys, json; print json.load(sys.stdin)['AUX']")})
exten => s,n,SayDigits(${result})
exten => s,n,Hangup

when I curl -s ‘’ I get a JSON response with multiple fields. I need the value of only one field.

In the Linux command line, when I run:
curl -s ‘’ | python -c “import sys, json; print json.load(sys.stdin)[‘AUX’]”)})

It works. Linux returns a number result (e.g. 10)

When I try to bake that into the dial plan I get an error:
[2016-10-26 15:40:36] WARNING[13399][C-00002c77]: pbx.c:4771 pbx_substitute_variables_helper_full: Error in extension logic (missing ‘}’)
[2016-10-26 15:40:36] WARNING[13399][C-00002c77]: pbx.c:4274 func_args: Can’t find trailing parenthesis for function ‘SHELL(curl -s ‘’ | python -c "import sys, jso’?

It seems like I am missing a parentheses, but I don’t see where. Any ideas?

Possibly because your call to SHELL returns an included newline?

always include a noop or two while debugging

(asterisk also has a curl command builtin)

1 Like

Thanks dicko, got me pointed in the right direction.

curl -s ‘’ | python -c “import sys, json; print json.load(sys.stdin)[‘AUX’]”)})

In the shell the ; is being treated as a comment indicator. You have to escape it by putting \ in front of it:

Set(result=${SHELL(curl -s ‘’ | python -c “import sys, json; print json.load(sys.stdin)[‘AUX’]”)})

This returns the correct result (in this example just 10). I was exploring the asterisk cURL command, but was having trouble getting just the one data point (the JSON package has 10).

Thanks again!

1 Like