Sample code for 30+ languages & platforms
Lua

SimpleTexting - Send SMS Message

See more SimpleTexting Examples

Send a text message to an individual contact.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

-- Implements the following CURL command:

-- curl --request POST \
--   --url 'https://app2.simpletexting.com/v1/send?token=YOUR_API_TOKEN&phone=SOME_STRING_VALUE&message=SOME_STRING_VALUE' \
--   --header 'accept: application/json' \
--   --header 'content-type: application/x-www-form-urlencoded'

-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code

http:set_request_header("accept", "application/json")
http:set_request_header("content-type", "application/x-www-form-urlencoded")

local req = chilkat.HttpRequest.new()
req:add_param("token", "YOUR_API_TOKEN")
req:add_param("phone", "SOME_10_DIGIT_PHONE_NUMBER")
req:add_param("message", "Hello: This is a sample text message with some punctuation: &%$@,;.")

req:add_header("Accept", "application/json")

req.http_verb = "POST"
req.content_type = "application/x-www-form-urlencoded"

local resp = chilkat.HttpResponse.new()
local success = http:http_req("https://app2.simpletexting.com/v1/send", req, resp)
if not success then
    print(http.last_error_text)
    return
end

local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    return
end

-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)

-- {
--   "code": 1,
--   "message": "The request succeeded",
--   "smsid": "5bec5b9d0a975a238808ffb2"
-- }

-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON

local code = jResp:int_of("code")
local message = jResp:string_of("message")
local smsid = jResp:string_of("smsid")