Skip to content

Latest commit

History

49 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

The official Go library for ClickSend v3 API

This is the official ClickSend Go SDK. Documentation can be found here.


Requirements


Installation

Step 1 — Verify Go is installed

go version

You should see output like go version go1.21.0 darwin/arm64. If not, install Go first.


Step 2 — Create a new project directory

mkdir clicksend-sms &&cd clicksend-sms

Step 3 — Initialise a Go module

go mod init clicksend-sms

Step 4 — Install the ClickSend Go SDK

go get github.com/ClickSend/clicksend-go

Run go mod tidy to pull in all transitive dependencies:

go mod tidy

Step 5 — Create main.go

Create 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 keyfromNum="FROM"// Approved sender ID or number e.g. "+61400000000"toNum="TO"// Recipient number in E.164 format e.g. "+61400000001"
)
funcmain() {
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},
})
iferr!=nil {
log.Fatalf("error sending SMS: %v", err)
}
fmt.Println("Response:", result)
}

Step 6 — Set your credentials

Replace the four constants at the top of main.go with your actual values:

ConstantWhere to find it
USERNAMEYour ClickSend account email
API_KEYDashboard → API Credentials
FROMAn approved sender ID or your ClickSend number (leave blank to use a shared number)
TOThe destination phone number in E.164 format e.g. +61400000001

Step 7 — Run the code

go run main.go

A 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!"
}
]
}
}

Project Structure

clicksend-sms/
├── main.go # Example — send a single SMS
├── go.mod # Module definition and SDK dependency
└── go.sum # Dependency checksums

Authentication

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.


Sending to Multiple Recipients

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"},
},
})

Further Reading

About

ClickSend Go SDK

Resources

Stars

5 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages