SmarthiveSMS API
  • Introduction
  • SMS
    • Send Single SMS
    • Send Multiple SMS
    • Status
    • Balance
    • Send SMS Sample Code
    • Callback
    • SMS DLR Error Codes
  • WhatsApp
    • Sending OTP
Powered by GitBook
On this page
  1. SMS

Send SMS Sample Code

Sample code using Send SMS API.

Sample PHP Code

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://smsapi-sur2.onrender.com/api/sms/send',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
"sender" : "SmartHive",
"recipients" : "09012345678",
"msg" : "THis is my message",
"type": 1,
"route": "OPEN"
}',
  CURLOPT_HTTPHEADER => array(
    'x-api-key: 88e9be59-6f47-4d81-89b4-############',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Sample Go code


package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://sms.smarthivetechsolution.com/api/sms/send"
  method := "POST"

  payload := strings.NewReader(`{
"sender" : "SmartHive",
"recipients" : "09012345678",
"msg" : "Testing SMS",
"type": 1,
"route": "COOP"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("x-api-key", "88e9be59-6f47-4d81-89b4-#############")
  req.Header.Add("Content-Type", "application/json")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
PreviousBalanceNextCallback

Last updated 1 year ago