Sample code for 30+ languages & platforms
AutoIt

SMSAPI - List Contacts

See more SMSAPI Examples

List Contacts

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oHttp = ObjCreate("Chilkat.Http")

; Implements the following CURL command:

; curl -X GET -H "Authorization: Bearer token_api_oauth" https://api.smsapi.com/contacts?phone_number=48500000000

; 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"

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://api.smsapi.com/contacts?phone_number=48500000000",$oSbResponseBody)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oHttp.LastHeader & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

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

; {
;   "size": 1,
;   "collection": [
;     {
;       "id": "5b83ba81a788494a0469490f",
;       "first_name": "name",
;       "last_name": "surname",
;       "phone_number": "48500000000",
;       "email": "bok@smsapi.com",
;       "gender": "male",
;       "city": "City",
;       "country": "Poland",
;       "source": "source",
;       "date_created": "2018-08-27T10:46:57+02:00",
;       "date_updated": "2018-08-27T10:46:57+02:00",
;       "groups": [
;         {
;           "id": "59a3ca1fa78849062837cd0c",
;           "name": "default",
;           "date_created": "2017-08-28T09:45:35+02:00",
;           "date_updated": "2017-08-28T09:45:35+02:00",
;           "description": "",
;           "created_by": "login",
;           "idx": null,
;           "contact_expire_after": null,
;           "contacts_count": null
;         }
;       ]
;     }
;   ]
; }

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

$oDate_created = ObjCreate("Chilkat.DtObj")
$oDate_updated = ObjCreate("Chilkat.DtObj")
Local $sId
Local $sFirst_name
Local $sLast_name
Local $sPhone_number
Local $sEmail
Local $sGender
Local $sCity
Local $sCountry
Local $source
Local $iJ
Local $iCount_j
Local $sName
Local $sDescription
Local $sCreated_by
Local $sIdx
Local $sContact_expire_after
Local $sContacts_count

Local $iSize = $oJResp.IntOf("size")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("collection")
While $i < $iCount_i
    $oJResp.I = $i
    $sId = $oJResp.StringOf("collection[i].id")
    $sFirst_name = $oJResp.StringOf("collection[i].first_name")
    $sLast_name = $oJResp.StringOf("collection[i].last_name")
    $sPhone_number = $oJResp.StringOf("collection[i].phone_number")
    $sEmail = $oJResp.StringOf("collection[i].email")
    $sGender = $oJResp.StringOf("collection[i].gender")
    $sCity = $oJResp.StringOf("collection[i].city")
    $sCountry = $oJResp.StringOf("collection[i].country")
    $source = $oJResp.StringOf("collection[i].source")
    $oJResp.DtOf("collection[i].date_created",False,$oDate_created)
    $oJResp.DtOf("collection[i].date_updated",False,$oDate_updated)
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("collection[i].groups")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sId = $oJResp.StringOf("collection[i].groups[j].id")
        $sName = $oJResp.StringOf("collection[i].groups[j].name")
        $oJResp.DtOf("collection[i].groups[j].date_created",False,$oDate_created)
        $oJResp.DtOf("collection[i].groups[j].date_updated",False,$oDate_updated)
        $sDescription = $oJResp.StringOf("collection[i].groups[j].description")
        $sCreated_by = $oJResp.StringOf("collection[i].groups[j].created_by")
        $sIdx = $oJResp.StringOf("collection[i].groups[j].idx")
        $sContact_expire_after = $oJResp.StringOf("collection[i].groups[j].contact_expire_after")
        $sContacts_count = $oJResp.StringOf("collection[i].groups[j].contacts_count")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend