Sample code for 30+ languages & platforms
Xbase++

SMSAPI - List Contacts

See more SMSAPI Examples

List Contacts

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL oDate_created
LOCAL oDate_updated
LOCAL cId
LOCAL cFirst_name
LOCAL cLast_name
LOCAL cPhone_number
LOCAL cEmail
LOCAL cGender
LOCAL cCity
LOCAL cCountry
LOCAL cSource
LOCAL j
LOCAL nCount_j
LOCAL cName
LOCAL cDescription
LOCAL cCreated_by
LOCAL cIdx
LOCAL cContact_expire_after
LOCAL cContacts_count
LOCAL nSize
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 -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 := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://api.smsapi.com/contacts?phone_number=48500000000", oSbResponseBody)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oSbResponseBody:destroy()
    RETURN
ENDIF

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

? "Response Body:"
? oJResp:Emit()

nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oHttp:LastHeader
    ? "Failed."
    oHttp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    RETURN
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 := CreateObject("Chilkat.DtObj")
oDate_updated := CreateObject("Chilkat.DtObj")

nSize := oJResp:IntOf("size")
i := 0
nCount_i := oJResp:SizeOfArray("collection")
DO WHILE i < nCount_i
    oJResp:I := i
    cId := oJResp:StringOf("collection[i].id")
    cFirst_name := oJResp:StringOf("collection[i].first_name")
    cLast_name := oJResp:StringOf("collection[i].last_name")
    cPhone_number := oJResp:StringOf("collection[i].phone_number")
    cEmail := oJResp:StringOf("collection[i].email")
    cGender := oJResp:StringOf("collection[i].gender")
    cCity := oJResp:StringOf("collection[i].city")
    cCountry := oJResp:StringOf("collection[i].country")
    cSource := oJResp:StringOf("collection[i].source")
    oJResp:DtOf("collection[i].date_created", 0, oDate_created)
    oJResp:DtOf("collection[i].date_updated", 0, oDate_updated)
    j := 0
    nCount_j := oJResp:SizeOfArray("collection[i].groups")
    DO WHILE j < nCount_j
        oJResp:J := j
        cId := oJResp:StringOf("collection[i].groups[j].id")
        cName := oJResp:StringOf("collection[i].groups[j].name")
        oJResp:DtOf("collection[i].groups[j].date_created", 0, oDate_created)
        oJResp:DtOf("collection[i].groups[j].date_updated", 0, oDate_updated)
        cDescription := oJResp:StringOf("collection[i].groups[j].description")
        cCreated_by := oJResp:StringOf("collection[i].groups[j].created_by")
        cIdx := oJResp:StringOf("collection[i].groups[j].idx")
        cContact_expire_after := oJResp:StringOf("collection[i].groups[j].contact_expire_after")
        cContacts_count := oJResp:StringOf("collection[i].groups[j].contacts_count")
        j := j + 1
    ENDDO
    i := i + 1
ENDDO

oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
oDate_created:destroy()
oDate_updated:destroy()