SMS Quickstart

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

On this page, you will...

  1. Sign up for a ClickSend account and get your API credentials.
  2. Set up your development environment to work with our API.
  3. Send your first SMS.

Before you start

  1. You need a ClickSend account with credit to start sending. If you don’t have an account, create one here.
  2. If you need to add more credit to your account, you can top up here. You’ll be credited $2 AUD free credit when you sign up.

Installation

Put the package under your project folder and import it  import ("clicksend/clicksend-go")

            
                go mod tidy

go build
            
        

Full Snippet

Below is the full snippet you can use to send an SMS. It includes placeholders that will need to be replaced when implementing the code in your project.

Placeholder

Replace with

USERNAME

Your ClickSend Username. Find it here.

API_KEY

Your ClickSend API key. Find it here.

SOURCE

The origin identifier for your API request, which could be the name of your application or the source location for the request.

MESSAGE

The content of your SMS message.

TO_PHONE_NUMBER

The phone number you're sending the message to, including the country code.

            
                import (
    "clicksend/clicksend-go"
    "context"
    "encoding/base64"
    "fmt"
)

func main() {
    username := " USERNAME"
    password := "PASSWORD"
    to_phone := "TO_PHONE_NUMBER"
    source := "SOURCE"
    message := "MESSAGE"

    authHeader := base64.StdEncoding.EncodeToString([]byte(username + ":" + password))

    config := clicksend.NewConfiguration()
    config.DefaultHeader["Authorization"] = "Basic " + authHeader

    client := clicksend.NewAPIClient(config)

    sampleMessage := clicksend.SmsMessage{
        To:     to_phone,
        Source: source,
        Body:   message,
    }
    messageCollection := clicksend.SmsMessageCollection{Messages: []clicksend.SmsMessage{sampleMessage}}

    body, smsApiResponse, err := client.SMSApi.SmsSendPost(context.Background(), messageCollection)

    if err != nil {
        fmt.Println("Error sending SMS:", err)
        return
    }

    fmt.Println("HEADER ", smsApiResponse)

    fmt.Println("SMS sent successfully. BODY :", body)
}
            
        

The code explained

Import functions

Start by preparing your environment to use the ClickSend API. Import the necessary modules, including the ClickSend client library and exception handling classes.

            
                import (
    "clicksend/clicksend-go"
    "context"
    "encoding/base64"
    "fmt")
            
        

Authorisation

Next, set up your Username and API Key so you can use the ClickSend API in your project.

In the following snippet, simply replace the placeholders ‘USERNAME’ and ‘API_KEY’ with your own Username and API Key. These can be found on your Dashboard here.

            
                    username := " USERNAME"
    password := "PASSWORD"
    to_phone := "TO_PHONE_NUMBER"
    source := "SOURCE"
    message := "MESSAGE"
            
        

Create an instance of the API class

The following line of code will create an instance of the ACCOUNTAPI class, which is configured to use the APICLIENT with the credentials that we set up in the previous step. This instance will allow you to interact with the ClickSend API's account-related functionality.

            
                authHeader := base64.StdEncoding.EncodeToString([]byte(username + ":" + password))

config := clicksend.NewConfiguration()
config.DefaultHeader["Authorization"] = "Basic " + authHeader

client := clicksend.NewAPIClient(config)
            
        

Configure your message

Next, configure the content of your message and define who you’re sending to-and-from.

Here you will want to replace the placeholder ‘SOURCE’ with your preferred source (eg. the name of your application). This is not seen by recipients, but will help you to identify messages sent from various applications.

Replace “MESSAGE” with a message of your choice, and replace “TO_PHONE_NUMBER” with the number that you’ll be sending the message to.

For testing purposes, we recommend you start by sending to your own number.

For additional properties that you can use here, see the Full API Reference.

            
                 sampleMessage := clicksend.SmsMessage{
        To:    “TO_PHONE_NUMBER”,
        Source: ”SOURCE”,
        Body:   “MESSAGE”,}
            
        

Send SMS message

Finally, try to call the SMS_SEND_POST method using the API_INSTANCE you've created. If everything works as expected then it will print the formatted response.

If an exception occurs during the API call, it catches the APIEXCEPTION and prints an error message with the exception details. This structure helps you handle both successful API calls and potential errors that might occur during the process.

            
                messageCollection := clicksend.SmsMessageCollection{Messages:[]clicksend.SmsMessage{sampleMessage}}

    body, smsApiResponse, err := client.SMSApi.SmsSendPost(context.Background(), messageCollection)

    if err != nil {
        fmt.Println("Error sending SMS:", err)
        return
    }

    fmt.Println("HEADER ", smsApiResponse)

    fmt.Println("SMS sent successfully. BODY :", body)

            
        

Two people at a race starting line graphic

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.