Sample code for 30+ languages & platforms
Delphi DLL 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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
http: HCkHttp;
query: HCkHttpRequest;
sender: PWideChar;
resp: HCkHttpResponse;
reply: HCkJsonObject;
parsed: Boolean;
count: Integer;
i: Integer;
resultNumber: Integer;
messageId: PWideChar;

begin
success := False;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
http := CkHttp_Create();
CkHttp_putRequireSslCertVerify(http,True);

//  Use the key issued for this HTTP integration. Chilkat encodes each query value.
query := CkHttpRequest_Create();
CkHttpRequest_putHttpVerb(query,'GET');
CkHttpRequest_AddHeader(query,'Accept','application/json');
CkHttpRequest_AddParam(query,'apiKey','HTTP_API_KEY');
CkHttpRequest_AddParam(query,'to','PHONE_NUMBER');
CkHttpRequest_AddParam(query,'content','Test message: pickup between 2 & 4.');
sender := '';
if (sender <> '') then
  begin
    CkHttpRequest_AddParam(query,'from',sender);
  end;
resp := CkHttpResponse_Create();
success := CkHttp_HttpReq(http,'https://platform.clickatell.com/messages/http/send',query,resp);
if (CkHttpResponse_getStatusCode(resp) = 0) then
  begin
    Memo1.Lines.Add('The send outcome is unknown. Check the message report before resending.');
    Exit;
  end;
reply := CkJsonObject_Create();
parsed := CkJsonObject_Load(reply,CkHttpResponse__bodyStr(resp));
if ((success <> True) or ((CkHttpResponse_getStatusCode(resp) <> 202))) then
  begin
    Memo1.Lines.Add('Clickatell returned HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
    if (parsed = True) then
      begin
        if (CkJsonObject_HasMember(reply,'errorDescription') = True) then
          begin
            Memo1.Lines.Add(CkJsonObject__stringOf(reply,'errorDescription'));
          end;
      end;
    Exit;
  end;
if (parsed <> True) then
  begin
    Memo1.Lines.Add('Expected a JSON response.');
    Exit;
  end;
//  A request-level error applies to the submission as a whole.
if (CkJsonObject_HasMember(reply,'errorCode') = True) then
  begin
    if (CkJsonObject_IsNullOf(reply,'errorCode') <> True) then
      begin
        Memo1.Lines.Add('Submission error ' + CkJsonObject__stringOf(reply,'errorCode') + '  ' + CkJsonObject__stringOf(reply,'errorDescription'));
        Exit;
      end;
  end;
count := CkJsonObject_SizeOfArray(reply,'messages');
if (count <= 0) then
  begin
    Memo1.Lines.Add('No recipient results returned. Check the message report before resending.');
    Exit;
  end;
i := 0;
while (i < count) do
  begin
    CkJsonObject_putI(reply,i);
    resultNumber := i + 1;
    //  JsonTypeOf returns 5 for a JSON boolean.
    if (CkJsonObject_JsonTypeOf(reply,'messages[i].accepted') <> 5) then
      begin
        Memo1.Lines.Add('Result ' + IntToStr(resultNumber) + ' has no acceptance flag.');
      end
    else
      begin
        if (CkJsonObject_BoolOf(reply,'messages[i].accepted') = True) then
          begin
            messageId := CkJsonObject__stringOf(reply,'messages[i].apiMessageId');
            if ((CkJsonObject_JsonTypeOf(reply,'messages[i].apiMessageId') <> 1) or (messageId = '')) then
              begin
                Memo1.Lines.Add('Result ' + IntToStr(resultNumber) + ' was accepted without a tracking ID.');
              end
            else
              begin
                Memo1.Lines.Add('Result ' + IntToStr(resultNumber) + ' accepted. Message ID: ' + messageId);
              end;
          end
        else
          begin
            Memo1.Lines.Add('Result ' + IntToStr(resultNumber) + ' rejected: ' + CkJsonObject__stringOf(reply,'messages[i].errorCode') + '  ' + CkJsonObject__stringOf(reply,'messages[i].errorDescription'));
          end;
      end;
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkHttpRequest_Dispose(query);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(reply);