Xbase++
Xbase++
SMSAPI - Get User Account Information
See more SMSAPI Examples
Get a list of subusers.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJarrResp
LOCAL nRespStatusCode
LOCAL oJson
LOCAL cId
LOCAL cUsername
LOCAL cActive
LOCAL cDescription
LOCAL cFrom_account
LOCAL cPer_month
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// 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.
oHttp:AuthToken := "token_api_oauth"
oHttp:SetRequestHeader("Content-Type", "application/json")
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://api.smsapi.com/subusers", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJarrResp := CreateObject("Chilkat.JsonArray")
oJarrResp:LoadSb(oSbResponseBody)
oJarrResp:EmitCompact := 0
? "Response Body:"
? oJarrResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oHttp:destroy()
oSbResponseBody:destroy()
oJarrResp:destroy()
RETURN
ENDIF
// 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
i := 0
nCount_i := oJarrResp:Size
DO WHILE i < nCount_i
oJson := oJarrResp:ObjectAt(i)
cId := oJson:StringOf("id")
cUsername := oJson:StringOf("username")
cActive := oJson:StringOf("active")
cDescription := oJson:StringOf("description")
cFrom_account := oJson:StringOf("from_account")
cPer_month := oJson:StringOf("per_month")
oJson:destroy()
i := i + 1
ENDDO
oHttp:destroy()
oSbResponseBody:destroy()
oJarrResp:destroy()