Sample code for 30+ languages & platforms
Delphi DLL

SMSAPI - List Contacts

See more SMSAPI Examples

List Contacts

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, DtObj, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
date_created: HCkDtObj;
date_updated: HCkDtObj;
id: PWideChar;
first_name: PWideChar;
last_name: PWideChar;
phone_number: PWideChar;
email: PWideChar;
gender: PWideChar;
city: PWideChar;
country: PWideChar;
source: PWideChar;
j: Integer;
count_j: Integer;
name: PWideChar;
description: PWideChar;
created_by: PWideChar;
idx: PWideChar;
contact_expire_after: PWideChar;
contacts_count: PWideChar;
size: Integer;
i: Integer;
count_i: Integer;

begin
success := False;

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

http := CkHttp_Create();

// 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.
CkHttp_putAuthToken(http,'token_api_oauth');

sbResponseBody := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://api.smsapi.com/contacts?phone_number=48500000000',sbResponseBody);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttp__lastHeader(http));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

// 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

date_created := CkDtObj_Create();
date_updated := CkDtObj_Create();

size := CkJsonObject_IntOf(jResp,'size');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'collection');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    id := CkJsonObject__stringOf(jResp,'collection[i].id');
    first_name := CkJsonObject__stringOf(jResp,'collection[i].first_name');
    last_name := CkJsonObject__stringOf(jResp,'collection[i].last_name');
    phone_number := CkJsonObject__stringOf(jResp,'collection[i].phone_number');
    email := CkJsonObject__stringOf(jResp,'collection[i].email');
    gender := CkJsonObject__stringOf(jResp,'collection[i].gender');
    city := CkJsonObject__stringOf(jResp,'collection[i].city');
    country := CkJsonObject__stringOf(jResp,'collection[i].country');
    source := CkJsonObject__stringOf(jResp,'collection[i].source');
    CkJsonObject_DtOf(jResp,'collection[i].date_created',False,date_created);
    CkJsonObject_DtOf(jResp,'collection[i].date_updated',False,date_updated);
    j := 0;
    count_j := CkJsonObject_SizeOfArray(jResp,'collection[i].groups');
    while j < count_j do
      begin
        CkJsonObject_putJ(jResp,j);
        id := CkJsonObject__stringOf(jResp,'collection[i].groups[j].id');
        name := CkJsonObject__stringOf(jResp,'collection[i].groups[j].name');
        CkJsonObject_DtOf(jResp,'collection[i].groups[j].date_created',False,date_created);
        CkJsonObject_DtOf(jResp,'collection[i].groups[j].date_updated',False,date_updated);
        description := CkJsonObject__stringOf(jResp,'collection[i].groups[j].description');
        created_by := CkJsonObject__stringOf(jResp,'collection[i].groups[j].created_by');
        idx := CkJsonObject__stringOf(jResp,'collection[i].groups[j].idx');
        contact_expire_after := CkJsonObject__stringOf(jResp,'collection[i].groups[j].contact_expire_after');
        contacts_count := CkJsonObject__stringOf(jResp,'collection[i].groups[j].contacts_count');
        j := j + 1;
      end;

    i := i + 1;
  end;

CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
CkDtObj_Dispose(date_created);
CkDtObj_Dispose(date_updated);

end;