SMS Go API example


package main

import (
  "encoding/json"
  "net/http"
  "log"
  "bytes"
)

func main() {

  token := "your.token"; //Your first token must be generated on our plateform at https://app.smsup.ch/developers/api-tokens

  payload := map[string]interface{}{
    "sms": map[string]interface{}{
      "message": map[string]interface{}{
        "text": "Hello, it's me. I was wondering if after all these years you'd like to meet",
        "pushtype": "marketing",
        "sender": "ADELE",
      },
      "recipients": map[string]interface{}{
        "gsm": []interface{}{
          map[string]interface{}{
            "gsmsmsid": "100",
            "value": "41781234567",
          },
          map[string]interface{}{
            "gsmsmsid": "100",
            "value": "41781234567",
          },
        },
      },
    },
  }

  jsonPayload, err := json.Marshal(payload)
  if err != nil {
    log.Fatalln(err)
  }

  req, err := http.NewRequest("POST", "https://api.smsup.ch", bytes.NewBuffer(jsonPayload))
  req.Header.Add("Authorization", "Bearer " + token)
  req.Header.Add("Accept", "application/json")
  client := &http.Client{}
  res, err := client.Do(req)
  if err != nil {
    log.Fatalln(err)
  }

  var result map[string]interface{}

  json.NewDecoder(res.Body).Decode(&result)

  log.Println(result)
}