Sample code for 30+ languages & platforms
Lazarus Pascal Requires Chilkat v11.0.0+

Clickatell HTTP API: Send an SMS with query parameters

See more Clickatell Examples

Use an SMS integration configured for HTTP in the Clickatell Portal. The endpoint takes apiKey, to, and content as query parameters. Pass raw values to Chilkat so it can encode spaces, ampersands, and other reserved characters. Supply a country code and phone number as digits. Set from when your two-way integration requires a sender.

The URL contains the API key, recipient, and message text. Keep full request URLs out of logs and browser history. Check the per-message result after HTTP 202. If the connection is interrupted, check the Portal message report before resending. For the header-authenticated JSON workflow, see Send an SMS with One API.

Clickatell API reference

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.HttpRequest,
  Chilkat.HttpResponse,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  query: THttpRequest;
  sender: string;
  resp: THttpResponse;
  reply: TJsonObject;
  parsed: Boolean;
  count: Integer;
  i: Integer;
  resultNumber: Integer;
  messageId: string;

begin
  success := False;

  //  Assumes Chilkat is unlocked. See Global Unlock Sample.
  http := THttp.Create;
  http.RequireSslCertVerify := True;

  //  Use the key issued for this HTTP integration. Chilkat encodes each query value.
  query := THttpRequest.Create;
  query.HttpVerb := 'GET';
  query.AddHeader('Accept','application/json');
  query.AddParam('apiKey','HTTP_API_KEY');
  query.AddParam('to','PHONE_NUMBER');
  query.AddParam('content','Test message: pickup between 2 & 4.');
  sender := '';
  if (sender <> '') then
    begin
      query.AddParam('from',sender);
    end;
  resp := THttpResponse.Create;
  success := http.HttpReq('https://platform.clickatell.com/messages/http/send',query,resp);
  if (resp.StatusCode = 0) then
    begin
      WriteLn('The send outcome is unknown. Check the message report before resending.');
      Exit;
    end;
  reply := TJsonObject.Create;
  parsed := reply.Load(resp.BodyStr);
  if ((success <> True) or ((resp.StatusCode <> 202))) then
    begin
      WriteLn('Clickatell returned HTTP ' + resp.StatusCode);
      if (parsed = True) then
        begin
          if (reply.HasMember('errorDescription') = True) then
            begin
              WriteLn(reply.StringOf('errorDescription'));
            end;
        end;
      Exit;
    end;
  if (parsed <> True) then
    begin
      WriteLn('Expected a JSON response.');
      Exit;
    end;
  //  A request-level error applies to the submission as a whole.
  if (reply.HasMember('errorCode') = True) then
    begin
      if (reply.IsNullOf('errorCode') <> True) then
        begin
          WriteLn('Submission error ' + reply.StringOf('errorCode') + '  ' + reply.StringOf('errorDescription'));
          Exit;
        end;
    end;
  count := reply.SizeOfArray('messages');
  if (count <= 0) then
    begin
      WriteLn('No recipient results returned. Check the message report before resending.');
      Exit;
    end;
  i := 0;
  while (i < count) do
    begin
      reply.I := i;
      resultNumber := i + 1;
      //  JsonTypeOf returns 5 for a JSON boolean.
      if (reply.JsonTypeOf('messages[i].accepted') <> 5) then
        begin
          WriteLn('Result ' + resultNumber + ' has no acceptance flag.');
        end
      else
        begin
          if (reply.BoolOf('messages[i].accepted') = True) then
            begin
              messageId := reply.StringOf('messages[i].apiMessageId');
              if ((reply.JsonTypeOf('messages[i].apiMessageId') <> 1) or (messageId = '')) then
                begin
                  WriteLn('Result ' + resultNumber + ' was accepted without a tracking ID.');
                end
              else
                begin
                  WriteLn('Result ' + resultNumber + ' accepted. Message ID: ' + messageId);
                end;
            end
          else
            begin
              WriteLn('Result ' + resultNumber + ' rejected: ' + reply.StringOf('messages[i].errorCode') + '  ' + reply.StringOf('messages[i].errorDescription'));
            end;
        end;
      i := i + 1;
    end;



  http.Free;
  query.Free;
  resp.Free;
  reply.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.