SMS Quickstart

The fastest way to get started with ClickSend API in your preferred coding language.

This guide is for the current version of the Go SDK.

Looking for v1? See our Quickstart guide for our Go v1 SDK.

Send your first SMS with the official ClickSend Go SDK in under 5 minutes.

1. Prerequisites

Before you start, make sure you have:

Requirement

Details

A ClickSend account

Sign up free if you don't have one. New accounts get free credit to test with.

API credentials

Your username and API key, both on the API Credentials page of the dashboard. You'll authenticate with these, not your dashboard login password.

Go 1.23 or newer

Check with go version.

Account credit

Sending SMS consumes credit. Free trial credit is enough for this guide; top up on the Billing page if you get an INSUFFICIENT_CREDIT error later.

2. Install

go get github.com/ClickSend/clicksend-go-v2/v6

3. Configure the client

The SDK authenticates with HTTP Basic auth, applied per-request via a context.Context carrying a BasicAuth value. Never hard-code real credentials — load them from environment variables:

export CLICKSEND_USERNAME="your-clicksend-username"
export CLICKSEND_API_KEY="your-clicksend-api-key"

package main

import (
    "context"
    "os"

    clicksend "github.com/ClickSend/clicksend-go-v2/v6"
)

func main() {
    cfg := clicksend.NewConfiguration()
    client := clicksend.NewAPIClient(cfg)

    auth := context.WithValue(context.Background(), clicksend.ContextBasicAuth, clicksend.BasicAuth{
        UserName: os.Getenv("CLICKSEND_USERNAME"), // placeholder: your ClickSend username
        Password: os.Getenv("CLICKSEND_API_KEY"),  // placeholder: your ClickSend API key
    })

    _ = auth
    _ = client
}

client is now an authenticated client for every ClickSend resource — each is a field on it (client.SmsAPI, client.MmsAPI, client.ManagementAPI, ...). Pass the same auth context to every call.

4. Send your first SMS

This is a complete, runnable example. Save it as send_sms.go, set the two environment variables from step 3, replace the to number with a real one, and run it.

package main

import (
    "context"
    "fmt"
    "os"

    clicksend "github.com/ClickSend/clicksend-go-v2/v6"
)

func main() {
    cfg := clicksend.NewConfiguration()
    client := clicksend.NewAPIClient(cfg)

    auth := context.WithValue(context.Background(), clicksend.ContextBasicAuth, clicksend.BasicAuth{
        UserName: os.Getenv("CLICKSEND_USERNAME"),
        Password: os.Getenv("CLICKSEND_API_KEY"),
    })

    message := clicksend.NewSendSmsRequestMessagesInnerWithDefaults()   message.SetFrom("YOUR_SENDER_ID") // placeholder: e.g. a ClickSend number, or omit to use your default sender
    message.SetBody("Hello from ClickSend!")
    message.SetTo("+61411111111") // placeholder: recipient in E.164 format

    sendSmsRequest := clicksend.NewSendSmsRequestWithDefaults()
    sendSmsRequest.SetMessages([]clicksend.SendSmsRequestMessagesInner{*message})

    result, httpResp, err := client.SmsAPI.SendSms(auth).SendSmsRequest(*sendSmsRequest).Execute()
    if err != nil {
        status := 0
        if httpResp != nil {
            status = httpResp.StatusCode
        }
        fmt.Printf("Failed to send SMS: %d %v\n", status, err)
        return
    }

    fmt.Printf("%+v\n", result)
}

Run it:

go run send_sms.go

5. Understand the response

client.SmsAPI.SendSms(...).Execute() returns (*SendSms, *http.Response, error). Every model field is a pointer, so use the generated pointer-safe getters rather than dereferencing fields directly:

{
  "http_code": 200,
  "response_code": "SUCCESS",
  "response_msg": "Messages queued for delivery.",
  "data": {
    "total_price": 0.0388,
    "total_count": 1,
    "queued_count": 1,
    "blocked_count": 0,
    "messages": [
      {
        "to": "+61411111111",
        "body": "Hello from ClickSend!",
        "from": "SENDERID",
        "message_id": "6811A5CE-E374-5D26-82F5-1D9E52FA9AB3",
        "message_parts": 1,
        "message_price": "0.0388",
        "status": "SUCCESS",
        "date": 1758434400
      }
    ]
  }
}

The fields you'll use most:

Field

Where

Meaning

Message ID

result.GetData().GetMessages()[0].GetMessageId()

The unique ID for this message. Quote this when contacting support or looking up delivery receipts.

Status

result.GetData().GetMessages()[0].GetStatus()

The outcome for this specific message (SUCCESS, INVALID_RECIPIENT, ...). Check this per message — a batch send can succeed overall while individual messages fail (see §6).

Cost

result.GetData().GetMessages()[0].GetMessagePrice()

Cost of this one message (string). result.GetData().GetTotalPrice() is the sum across every message in the request.

message := result.GetData().GetMessages()[0]
fmt.Println("Message ID:", message.GetMessageId())
fmt.Println("Status:", message.GetStatus())
fmt.Println("Cost:", message.GetMessagePrice())

6. Common errors

client.SmsAPI.SendSms(...).Execute() returns a non-nil error on a non-2xx HTTP response — check it before touching result. But ClickSend also reports some failures — like an invalid recipient in an otherwise-valid batch — inside a 200 OK response, which won't produce an error at all. Always check each message's own GetStatus(), not just whether err is non-nil.

result, httpResp, err := client.SmsAPI.SendSms(auth).SendSmsRequest(*sendSmsRequest).Execute()
if err != nil {
    status := 0
    if httpResp != nil {
        status = httpResp.StatusCode
    }
    fmt.Printf("HTTP error: %d %v\n", status, err)
    return
}

// Even on HTTP 200, check each message's own status
for _, message := range result.GetData().GetMessages() {
    if message.GetStatus() != "SUCCESS" {
        fmt.Printf("Message to %s failed: %s\n", message.GetTo(), message.GetStatus())
    }
}

Error

How it shows up

What it means

Fix

Authentication failure

err != nil, httpResp.StatusCode == 401 — the response body's response_code is MISSING_CREDENTIALS (no username/API key sent) or INVALID_CREDENTIALS (wrong username/API key).

Your BasicAuth{UserName, Password} doesn't match a valid ClickSend account, or an env var wasn't set.

Double-check CLICKSEND_USERNAME/CLICKSEND_API_KEY are set and copied exactly from the API Credentials page — use the API key, not your dashboard password.

Invalid recipient

Request usually still returns HTTP 200 (response_code: SUCCESS at the top level, err is nil) — the failure is on the individual message: message.GetStatus() is INVALID_RECIPIENT. This does not produce an error — you must check the status yourself.

The destination mobile number isn't a valid, deliverable number (bad format, wrong country, disconnected, etc).

Validate/normalize numbers to E.164 (e.g. +61411111111) before sending, and surface per-message status values to your own logs or users.

Insufficient balance

response_code (or a message's GetStatus()) is INSUFFICIENT_CREDIT, typically alongside httpResp.StatusCode == 400 when it blocks the whole request.

Your account has run out of message credit.

Top up credit on the Billing page, or check balance first with client.ManagementAPI.ViewAccountDetails(auth).Execute().

Next steps

Start sprinting with our API docs

Get all the detail you'll ever need in our full API docs. Learn how to launch your own features or integrate with others.