> ## Documentation Index
> Fetch the complete documentation index at: https://docs-staging.termii.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates API

> Templates API helps businesses set a template for the one-time-passwords (pins) sent to their customers via whatsapp or sms.

## Device Template

**Endpoint:** `https://BASE_URL/api/send/template`

**Request Type:** `POST`

**Sample Response:**

| Options      | Required | Description                                                                                                                                                                                                       |
| ------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| phone-number | yes      | *string* <br /> The destination phone number. Phone number must be in the international format (Example:`CompanyName`                                                                                             |
| device-id    | yes      | *string* <br /> Represents the Device ID for Whatsapp. It can be Alphanumeric. It should be passed when the message is sent via whatsapp (It can be found on the manage device page on your Termii dashboard)     |
| teplate-id   | yes      | *string* <br /> The ID of the template used                                                                                                                                                                       |
| api-key      | yes      | *string* <br /> Your API key (It can be found on your [Termii dashboard](https://api.termii.com)).                                                                                                                |
| data         | object   | *object* <br /> Represents an object of `key: value` pair. The keys for the data object can be found on the device subscription page on your dashboard. (`Example: {"product_name": "Termii", "otp" : 120435, })` |

<CodeGroup>
  ```json JSON theme={null}
  {
   "phone_number": "2347880234567",
   "device_id": "talert",
   "template_id": "1493-csdn3-ns34w-sd3434-dfdf",
   "api_key": "plain",
   "data": {
       "product_name": "Termii",
       "otp" : 120435,
       "expiry_time": "10 minutes"
  } 
  ```

  ```json JavaScript theme={null}
  var data = {
          "phone_number": "2347880234567",
          "device_id": "talert",
          "template_id": "1493-csdn3-ns34w-sd3434-dfdf",
          "api_key": "plain",
         "data": {
             "product_name": "Termii",
             "otp" : 120435,
             "expiry_time": "10 minutes"
         } 
        };

  var data = JSON.stringify(data);

  var xhr = new XMLHttpRequest();
  xhr.withCredentials = true;

  xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
  console.log(this.responseText);
  }
  });

  xhr.open("POST", " https://BASE_URL/api/send/template");
  xhr.setRequestHeader("Content-Type", "application/json");
  xhr.setRequestHeader("Content-Type", "application/json");

  xhr.send(data);
  ```

  ```json NodeJs theme={null}

  var request = require('request');
  var data = {
  "phone_number": "2347880234567",
  "device_id": "talert",
  "template_id": "1493-csdn3-ns34w-sd3434-dfdf",
  "api_key": "plain",
  "data": {
  "product_name": "Termii",
  "otp" : 120435,
  "expiry_time": "10 minutes"
  }
  };
  var options = {
  'method': 'POST',
  'url': ' https://BASE_URL/api/send/template',
  'headers': {
  'Content-Type': ['application/json', 'application/json']
  },
  body: JSON.stringify(data)

  };
  request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
  });
  ```

  ```json Python theme={null}

  import requests
  url = "https://BASE_URL/api/send/template"
  payload = {
        "phone_number": "2347880234567",
         "device_id": "talert",
         "template_id": "1493-csdn3-ns34w-sd3434-dfdf",
         "api_key": "plain",
         "data": {
             "product_name": "Termii",
             "otp" : 120435,
             "expiry_time": "10 minutes"
         }
     }
  headers = {
  'Content-Type': 'application/json',
  }
  response = requests.request("POST", url, headers=headers, json=payload)
  print(response.text)
  ```

  ```json C# theme={null}
  var client = new RestClient("https://BASE_URL/api/send/template");
  client.Timeout = -1;
  var request = new RestRequest(Method.GET);
  request.AddHeader("Content-Type", "application/json");
  request.AddParameter("application/json", " {\r\n \"phone_number\": \"2347880234567\",\r\n  \"device_id\": \"talert\",\r\n \"template_id\": \"1493-csdn3-ns34w-sd3434-dfdf\",\r\n  \"api_key\": \"plain\",\r\n  \"data\": {\r\n   \"product_name\": \"Termii\",\r\n   \"otp\" : 120435,\r\n  \"expiry_time\": \"10 minutes\"\r\n     } \r\n   }",  
                ParameterType.RequestBody);
  IRestResponse response = client.Execute(request);
  Console.WriteLine(response.Content);
  ```

  ```json Java theme={null}
  Unirest.setTimeouts(0, 0);
  HttpResponse<String> response = Unirest.POST(" https://BASE_URL/api/send/template")
  .header("Content-Type", "application/json")
  .body(" {\r\n \"phone_number\": \"2347880234567\",\r\n \"device_id\": \"talert\",\r\n \"template_id\": \"1493-csdn3-ns34w-sd3434-dfdf\",\r\n \"api_key\": \"plain\",\r\n \"data\": {\r\n \"product_name\": \"Termii\",\r\n \"otp\" : 120435,\r\n \"expiry_time\": \"10 minutes\"\r\n } \r\n   }")
  .asString();
  ```

  ```json Php theme={null}
  $curl = curl_init();

  curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://BASE_URL/api/send/template',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_POSTFIELDS =>' {
  "phone_number": "2347880234567",
  "device_id": "talert",
  "template_id": "1493-csdn3-ns34w-sd3434-dfdf",
  "api_key": "plain",
  "data": {
  "product_name": "Termii",
  "otp" : 120435,
  "expiry_time": "10 minutes"
  }
  }',
  CURLOPT_HTTPHEADER => array(
  'Content-Type: application/json'
  ),
  ));

  $response = curl_exec($curl);

  curl_close($curl);
  echo $response;
  ```
</CodeGroup>

**Response:**

```
   [
      {
          "code": "ok",
          "message_id": "2255298515609943356",
          "message": "Successfully Sent",
          "balance": "unlimited",
          "user": "Termii Inc."
      }
   ]
```
