Lua
Lua
SMSAPI - Get User Account Information
See more SMSAPI Examples
Get a list of subusers.Chilkat Lua Downloads
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 -i -H "Authorization: Bearer token_api_oauth" \
-- -H "Content-Type: application/json" -X GET https://api.smsapi.com/subusers
-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code
-- Adds the "Authorization: Bearer token_api_oauth" header.
http.auth_token = "token_api_oauth"
http:set_request_header("Content-Type", "application/json")
local sbResponseBody = chilkat.StringBuilder.new()
local success = http:quick_get_sb("https://api.smsapi.com/subusers", sbResponseBody)
if not success then
print(http.last_error_text)
return
end
local jarrResp = chilkat.JsonArray.new()
jarrResp:load_sb(sbResponseBody)
jarrResp.emit_compact = false
print("Response Body:")
print(jarrResp:emit())
local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(http.last_header)
print("Failed.")
return
end
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- [
-- {
-- "id": "5A5359173738303F2F95B7E2",
-- "username": "subuser1",
-- "active": "true",
-- "description": "null",
-- "from_account": "10.0000",
-- "per_month": "0"
-- },
-- {
-- "id": "5A5359173738303F2F95B7E2",
-- "username": "subuser2",
-- "active": "true",
-- "description": "null",
-- "from_account": "10.0000",
-- "per_month": "0"
-- }
-- ]
-- 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 json
local id = ""
local username = ""
local active = ""
local description = ""
local from_account = ""
local per_month = ""
local i = 0
local count_i = jarrResp.size
while i < count_i do
json = jarrResp:object_at(i)
id = json:string_of("id")
username = json:string_of("username")
active = json:string_of("active")
description = json:string_of("description")
from_account = json:string_of("from_account")
per_month = json:string_of("per_month")
i = i + 1
end