Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
Clickatell One API: Read the account balance and currency
See more Clickatell Examples
Request the messaging balance associated with a One API integration key. The response supplies both the decimal amount and its currency. Read the amount as text for display to preserve its precision. A zero balance is a valid result. For example, a billing dashboard can display 1267.92865 ZAR.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
http: TChilkatHttp;
resp: TChilkatHttpResponse;
reply: TChilkatJsonObject;
parsed: Integer;
begin
success := 0;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
http := TChilkatHttp.Create(Self);
http.RequireSslCertVerify := 1;
// Supply the key for this One API integration from application configuration.
http.SetRequestHeader('Authorization','ONE_API_KEY');
http.SetRequestHeader('Accept','application/json');
resp := TChilkatHttpResponse.Create(Self);
success := http.HttpNoBody('GET','https://platform.clickatell.com/v1/balance',resp.ControlInterface);
if (resp.StatusCode = 0) then
begin
Memo1.Lines.Add('No HTTP response. Check the connection and retry the lookup.');
Exit;
end;
reply := TChilkatJsonObject.Create(Self);
parsed := reply.Load(resp.BodyStr);
if ((success <> 1) or ((resp.StatusCode <> 200))) then
begin
Memo1.Lines.Add('Clickatell returned HTTP ' + IntToStr(resp.StatusCode));
if (parsed = 1) then
begin
if (reply.HasMember('error.description') = 1) then
begin
Memo1.Lines.Add(reply.StringOf('error.description'));
end;
end;
Exit;
end;
if (parsed <> 1) then
begin
Memo1.Lines.Add('Expected a JSON response.');
Exit;
end;
// JsonTypeOf returns 2 for a number and 1 for a string. Zero is a valid amount.
if ((reply.JsonTypeOf('balance') <> 2) or (reply.JsonTypeOf('currency') <> 1)) then
begin
Memo1.Lines.Add('The balance response is missing the amount or currency.');
Exit;
end;
Memo1.Lines.Add('Account balance: ' + reply.StringOf('balance') + ' ' + reply.StringOf('currency'));