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

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

#  Assumes Chilkat is unlocked. See Global Unlock Sample.
$http = New-Object Chilkat.Http
$http.RequireSslCertVerify = $true

#  Use the key issued for this HTTP integration. Chilkat encodes each query value.
$query = New-Object Chilkat.HttpRequest
$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 -ne "") {
    $query.AddParam("from",$sender)
}

$resp = New-Object Chilkat.HttpResponse
$success = $http.HttpReq("https://platform.clickatell.com/messages/http/send",$query,$resp)
if ($resp.StatusCode -eq 0) {
    $("The send outcome is unknown. Check the message report before resending.")
    exit
}

$reply = New-Object Chilkat.JsonObject
$parsed = $reply.Load($resp.BodyStr)
if (($success -ne $true) -or (($resp.StatusCode -ne 202))) {
    $("Clickatell returned HTTP " + $resp.StatusCode)
    if ($parsed -eq $true) {
        if ($reply.HasMember("errorDescription") -eq $true) {
            $($reply.StringOf("errorDescription"))
        }

    }

    exit
}

if ($parsed -ne $true) {
    $("Expected a JSON response.")
    exit
}

#  A request-level error applies to the submission as a whole.
if ($reply.HasMember("errorCode") -eq $true) {
    if ($reply.IsNullOf("errorCode") -ne $true) {
        $("Submission error " + $reply.StringOf("errorCode") + "  " + $reply.StringOf("errorDescription"))
        exit
    }

}

$count = $reply.SizeOfArray("messages")
if ($count -le 0) {
    $("No recipient results returned. Check the message report before resending.")
    exit
}

$i = 0
while (($i -lt $count)) {
    $reply.I = $i
    $resultNumber = $i + 1
    #  JsonTypeOf returns 5 for a JSON boolean.
    if ($reply.JsonTypeOf("messages[i].accepted") -ne 5) {
        $("Result " + $resultNumber + " has no acceptance flag.")
    }
    else {
        if ($reply.BoolOf("messages[i].accepted") -eq $true) {
            $messageId = $reply.StringOf("messages[i].apiMessageId")
            if (($reply.JsonTypeOf("messages[i].apiMessageId") -ne 1) -or ($messageId -eq "")) {
                $("Result " + $resultNumber + " was accepted without a tracking ID.")
            }
            else {
                $("Result " + $resultNumber + " accepted. Message ID: " + $messageId)
            }

        }
        else {
            $("Result " + $resultNumber + " rejected: " + $reply.StringOf("messages[i].errorCode") + "  " + $reply.StringOf("messages[i].errorDescription"))
        }

    }

    $i = $i + 1
}