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

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Query
string ls_Sender
oleobject loo_Resp
oleobject loo_Reply
long li_Parsed
long li_Count
long i
long li_ResultNumber
string ls_MessageId

li_Success = 0

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Http.RequireSslCertVerify = 1

//  Use the key issued for this HTTP integration. Chilkat encodes each query value.
loo_Query = create oleobject
li_rc = loo_Query.ConnectToNewObject("Chilkat.HttpRequest")

loo_Query.HttpVerb = "GET"
loo_Query.AddHeader("Accept","application/json")
loo_Query.AddParam("apiKey","HTTP_API_KEY")
loo_Query.AddParam("to","PHONE_NUMBER")
loo_Query.AddParam("content","Test message: pickup between 2 & 4.")
ls_Sender = ""
if ls_Sender <> "" then
    loo_Query.AddParam("from",ls_Sender)
end if

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpReq("https://platform.clickatell.com/messages/http/send",loo_Query,loo_Resp)
if loo_Resp.StatusCode = 0 then
    Write-Debug "The send outcome is unknown. Check the message report before resending."
    destroy loo_Http
    destroy loo_Query
    destroy loo_Resp
    return
end if

loo_Reply = create oleobject
li_rc = loo_Reply.ConnectToNewObject("Chilkat.JsonObject")

li_Parsed = loo_Reply.Load(loo_Resp.BodyStr)
if (li_Success <> 1) OR ((loo_Resp.StatusCode <> 202)) then
    Write-Debug "Clickatell returned HTTP " + string(loo_Resp.StatusCode)
    if li_Parsed = 1 then
        if loo_Reply.HasMember("errorDescription") = 1 then
            Write-Debug loo_Reply.StringOf("errorDescription")
        end if

    end if

    destroy loo_Http
    destroy loo_Query
    destroy loo_Resp
    destroy loo_Reply
    return
end if

if li_Parsed <> 1 then
    Write-Debug "Expected a JSON response."
    destroy loo_Http
    destroy loo_Query
    destroy loo_Resp
    destroy loo_Reply
    return
end if

//  A request-level error applies to the submission as a whole.
if loo_Reply.HasMember("errorCode") = 1 then
    if loo_Reply.IsNullOf("errorCode") <> 1 then
        Write-Debug "Submission error " + loo_Reply.StringOf("errorCode") + "  " + loo_Reply.StringOf("errorDescription")
        destroy loo_Http
        destroy loo_Query
        destroy loo_Resp
        destroy loo_Reply
        return
    end if

end if

li_Count = loo_Reply.SizeOfArray("messages")
if li_Count <= 0 then
    Write-Debug "No recipient results returned. Check the message report before resending."
    destroy loo_Http
    destroy loo_Query
    destroy loo_Resp
    destroy loo_Reply
    return
end if

i = 0
do while (i < li_Count)
    loo_Reply.I = i
    li_ResultNumber = i + 1
    //  JsonTypeOf returns 5 for a JSON boolean.
    if loo_Reply.JsonTypeOf("messages[i].accepted") <> 5 then
        Write-Debug "Result " + string(li_ResultNumber) + " has no acceptance flag."
    else
        if loo_Reply.BoolOf("messages[i].accepted") = 1 then
            ls_MessageId = loo_Reply.StringOf("messages[i].apiMessageId")
            if (loo_Reply.JsonTypeOf("messages[i].apiMessageId") <> 1) OR (ls_MessageId = "") then
                Write-Debug "Result " + string(li_ResultNumber) + " was accepted without a tracking ID."
            else
                Write-Debug "Result " + string(li_ResultNumber) + " accepted. Message ID: " + ls_MessageId
            end if

        else
            Write-Debug "Result " + string(li_ResultNumber) + " rejected: " + loo_Reply.StringOf("messages[i].errorCode") + "  " + loo_Reply.StringOf("messages[i].errorDescription")
        end if

    end if

    i = i + 1
loop


destroy loo_Http
destroy loo_Query
destroy loo_Resp
destroy loo_Reply