Delphi DLL
Delphi DLL
SMSAPI - Get User Account Information
See more SMSAPI Examples
Get a list of subusers.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, JsonArray, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
sbResponseBody: HCkStringBuilder;
jarrResp: HCkJsonArray;
respStatusCode: Integer;
json: HCkJsonObject;
id: PWideChar;
username: PWideChar;
active: PWideChar;
description: PWideChar;
from_account: PWideChar;
per_month: PWideChar;
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 -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.
CkHttp_putAuthToken(http,'token_api_oauth');
CkHttp_SetRequestHeader(http,'Content-Type','application/json');
sbResponseBody := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://api.smsapi.com/subusers',sbResponseBody);
if (success = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
jarrResp := CkJsonArray_Create();
CkJsonArray_LoadSb(jarrResp,sbResponseBody);
CkJsonArray_putEmitCompact(jarrResp,False);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonArray__emit(jarrResp));
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)
// [
// {
// "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;
count_i := CkJsonArray_getSize(jarrResp);
while i < count_i do
begin
json := CkJsonArray_ObjectAt(jarrResp,i);
id := CkJsonObject__stringOf(json,'id');
username := CkJsonObject__stringOf(json,'username');
active := CkJsonObject__stringOf(json,'active');
description := CkJsonObject__stringOf(json,'description');
from_account := CkJsonObject__stringOf(json,'from_account');
per_month := CkJsonObject__stringOf(json,'per_month');
CkJsonObject_Dispose(json);
i := i + 1;
end;
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonArray_Dispose(jarrResp);
end;