Hey guys, I’m trying to post data in json format from asterisk dialplan. General idea is to post some data to external CRM when call is answered from an agent. I’m not using CRM link and trying to do something similar to the below post but using json format.
most likely I have a syntax error…in my custom dialplan I included:
exten => s,1,Set(foo=$(CURL(https://mysite.com -s -o /var/log/asterisk/postresult.txt -H ‘Content-Type: application/json’ -d ‘{“email”: “email@address”,“number”: “some number”}’)))
Here, without trying to start figuring out the variables yet, I simply want to post that data “email@address” and “some number”. in that postresult.txt file I’m trying to log the curl reply.
If I run
curl https://mysite.com -s -o /var/log/asterisk/testdump.txt -H ‘Content-Type: application/json’ -d ‘{“email”: “email@address”,“number”: “some number”}’
from shell it works.
You need to review how the CURL function works in Asterisk. You function call is incorrect. CURL - Asterisk Documentation
CURL() takes two parameters, the URL and any post-data ie CURL(${URL},${POSTDATA}) if you want to set options review the CURLOPT() function CURLOPT - Asterisk Documentation
This is probably better done through AGI or stasis honestly. Once you start adding quotes and symbols and other stuff to dialplan directly you are asking for issues. Often in dialplan when I want to pass a block of data I base64 encode it then on the other end I decode it. Then there is no concerns of weird punctuation or whitespace blowing up the universe.