This is the official ClickSend Go SDK. Documentation can be found here.
- Go 1.18 or later
- A free ClickSend account — sign up here
- Your ClickSend username (email) and API key from the API Credentials page
go versionYou should see output like go version go1.21.0 darwin/arm64. If not, install Go first.
mkdir clicksend-sms && cd clicksend-smsgo mod init clicksend-smsgo get github.com/ClickSend/clicksend-goRun go mod tidy to pull in all transitive dependencies:
go mod tidyCreate a file named main.go in your project directory and paste the following code:
package main
import (
"context"
"fmt"
"log"
clicksend "github.com/ClickSend/clicksend-go"
)
const (
username = "USERNAME" // Your ClickSend username (email)
apiKey = "API_KEY" // Your ClickSend API key
fromNum = "FROM" // Approved sender ID or number e.g. "+61400000000"
toNum = "TO" // Recipient number in E.164 format e.g. "+61400000001"
)
func main() {
cfg := clicksend.NewConfiguration()
client := clicksend.NewAPIClient(cfg)
auth := context.WithValue(context.Background(), clicksend.ContextBasicAuth, clicksend.BasicAuth{
UserName: username,
Password: apiKey,
})
msg := clicksend.SmsMessage{
From: fromNum,
To: toNum,
Body: "Hello from the ClickSend Go SDK!",
Source: "go-sdk",
}
result, _, err := client.SMSApi.SmsSendPost(auth, clicksend.SmsMessageCollection{
Messages: []clicksend.SmsMessage{msg},
})
if err != nil {
log.Fatalf("error sending SMS: %v", err)
}
fmt.Println("Response:", result)
}Replace the four constants at the top of main.go with your actual values:
| Constant | Where to find it |
|---|---|
USERNAME |
Your ClickSend account email |
API_KEY |
Dashboard → API Credentials |
FROM |
An approved sender ID or your ClickSend number (leave blank to use a shared number) |
TO |
The destination phone number in E.164 format e.g. +61400000001 |
go run main.goA successful response looks like this:
{
"http_code": 200,
"response_code": "SUCCESS",
"response_msg": "Messages queued for delivery.",
"data": {
"total_price": 0.891,
"total_count": 1,
"queued_count": 1,
"messages": [
{
"status": "SUCCESS",
"message_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"to": "+61400000001",
"from": "ClickSend",
"body": "Hello from the ClickSend Go SDK!"
}
]
}
}clicksend-sms/
├── main.go # Example — send a single SMS
├── go.mod # Module definition and SDK dependency
└── go.sum # Dependency checksums
The SDK uses HTTP Basic Auth. Your username and API key are passed via context on every request:
auth := context.WithValue(context.Background(), clicksend.ContextBasicAuth, clicksend.BasicAuth{
UserName: "your_username",
Password: "your_api_key",
})Pass this auth context as the first argument to every API call.
Pass more than one SmsMessage in the Messages slice to send in a single API call (up to 1 000 messages per request):
result, _, err := client.SMSApi.SmsSendPost(auth, clicksend.SmsMessageCollection{
Messages: []clicksend.SmsMessage{
{From: fromNum, To: "+61400000001", Body: "Hello Alice!", Source: "go-sdk"},
{From: fromNum, To: "+61400000002", Body: "Hello Bob!", Source: "go-sdk"},
},
})