Hello! I'm trying to send a POST request in a Lua script after a session has ended in Freeswitch. I am fairly new to using the mod_curl application and have included my research sources below.
I've worked out most of the implementation but I'm stuck being unable to send a POST request successfully via the mod_curl app. I've confirmed my API info, url, and data is correct and I'm able to successfully run this command in the terminal of my test server. -
There's no problem when running this or any other external POST request tests. The issue is when using the mod_curl application in Lua I can't seem to get the request to clear.
I've confirmed that doing a GET request works no problem and the POST request is being received, but the body data is being rejected.
I'm using fs_cli to see any responses or errors but do not have access to the API server I'm calling, so I'm not sure what they are seeing when I request via mod_curl.
The response I keep getting is a rejection for "{"error":"Invalid from number."}". To fix this I've tried changing the from value to match the urlencoded format as well as many other approaches -
I've looked through all the documents I could find online but nothing explains exactly how this should be formatted besides (value1=value2&value3=value4).
I'm certain this response is from the API server I'm calling as I've dealt with it in the past. The issue is just a data formatting issue as the data I'm trying to pass is exactly how it should be in the working curl terminal command above. How do I properly format this data to be used in the mod_curl application api:execute("curl", postStr)?
Sources that helped me so far -
github.com
www.pbxforums.com
github.com
I've worked out most of the implementation but I'm stuck being unable to send a POST request successfully via the mod_curl app. I've confirmed my API info, url, and data is correct and I'm able to successfully run this command in the terminal of my test server. -
curl -X POST https://example.app/api/send -H "Content-Type: application/json" -H "Authorization: 'Bearer xxxTokenxxx:xxxAccountUUIDxxx" -d '{"to":"+15622133497", "from":"+19494324054", "message":"Hello world, you are beautiful."}'
There's no problem when running this or any other external POST request tests. The issue is when using the mod_curl application in Lua I can't seem to get the request to clear.
Code:
--Lua Code:
api = freeswitch.API();
postStr = "https://example.app/api/send append_headers 'Authorization: Bearer xxxTokenxxx:xxxAccountUUIDxxx' post to='+15622133497'&from='+19494324054'&message='Hello world, you are beautiful.'";
reply = api:execute("curl", postStr);
freeswitch.consoleLog("INFO", reply .. "\n")
I've confirmed that doing a GET request works no problem and the POST request is being received, but the body data is being rejected.
I'm using fs_cli to see any responses or errors but do not have access to the API server I'm calling, so I'm not sure what they are seeing when I request via mod_curl.
The response I keep getting is a rejection for "{"error":"Invalid from number."}". To fix this I've tried changing the from value to match the urlencoded format as well as many other approaches -
from='+19494324054'
from=+19494324054 (no quotes)
from=%2B19494324054 (replace '+' with url code)
etc..
I've looked through all the documents I could find online but nothing explains exactly how this should be formatted besides (value1=value2&value3=value4).
I'm certain this response is from the API server I'm calling as I've dealt with it in the past. The issue is just a data formatting issue as the data I'm trying to pass is exactly how it should be in the working curl terminal command above. How do I properly format this data to be used in the mod_curl application api:execute("curl", postStr)?
Sources that helped me so far -
Using Authorization header with mod_curl · Issue #1377 · signalwire/freeswitch
Is your feature request related to a problem? Please describe. I recently secured the API my FreeSwitch is communicating with, and now I get a 401 Unauthorized in response. Using curl in CLI, it's ...
mod_curl Whitespace
I'm using mod_curl to send a get request to an external API using a URL similar to this: https://api.sample.com/webhook/office-inbound-call?site=samplesite&callernum=${caller_id_number}&callerid=${caller_id_name} It's mostly working just fine however as the ${caller_id_name} has spaces in it...

freeswitch/src/mod/applications/mod_curl/mod_curl.c at master · signalwire/freeswitch
FreeSWITCH is a Software Defined Telecom Stack enabling the digital transformation from proprietary telecom switches to a versatile software implementation that runs on any commodity hardware. From...
Last edited: