Message template setup

Create a message template for a 2FA application.

Message template is the message body with the PIN placeholder that will be sent to end users. You may create many message templates per single application and therefore use the same application for different use cases or different languages. When you create your message template, you will be provided with the message template ID, which you will be using later when sending PINs. By referencing a message template ID, our system will generate a PIN, place the PIN in the message template and finally send the message with the PIN to the end user.

NOTE

Before creating a message template you need to create a 2FA application. Learn about each step of the setup process in the 2FA introduction.

On this page you will learn how to:

Resource

https://api.infobip.com/2fa/1/applications/{applicationId}/messages/

Resource description

Parameter Type Description
applicationId * string 2FA application ID for which the requested message is created.
messageId string Message template ID.
pinPlaceholder * string PIN code placeholder. Right before sending SMS, PIN code placeholder will be replaced with generated PIN code.
messageText * string Text of a message that will be sent. Message text must contain pinPlaceholder.
pinLength * int PIN code length.
pinType * string Type of PIN code that will be generated and sent as part of 2FA message. You can set PIN type to numeric, alpha, alphanumeric or hex so parameter must have one of these values: NUMERIC, ALPHA, ALPHANUMERIC or HEX.
repeatDTMF string In case PIN message is sent by Voice, DTMF code will enable replaying the message.
speechRate double In case PIN message is sent by Voice, the speed of speech can be set for the message. Supported range is from 0.5 to 2.
senderId * string The name that will appear as the sender of the 2FA message (Example: CompanyName).
language string Language code of language in which message text is written. It is used for reading the message when it is sent via voice. If no language is set, message will be read in English. Supported languages are listed in the table below.

Supported languages

Language code Language
en English
es Spanish
ca Catalan
zh-cn Chinese - simplified
zh-tw Chinese - traditional
da Danish
nl Dutch
fr French
de German
it Italian
ja Japanese
ko Korean
no Norwegian
pl Polish
pt-pt Portuguese
pt-br Brazilian Portuguese
ru Russian
sv Swedish
fi Finnish

Create a new message template

Use this method to create a new message template for an existing application.

POST https://api.infobip.com/2fa/1/applications/{applicationId}/messages

Request example

POST /2fa/1/applications/HJ675435E3A6EA43432G5F37A635KJ8B/messages HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json

{
  "pinType":"NUMERIC",
  "pinPlaceholder":"<pin>",
  "messageText":"Your pin is <pin>",
  "pinLength":4,
  "senderId":"Infobip 2FA",
  "language": "en",
  "repeatDTMF": "1#",
  "speechRate": 1
}
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.infobip.com/2fa/1/applications/HJ675435E3A6EA43432G5F37A635KJ8B/messages",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n  \"pinType\":\"NUMERIC\",\n  \"pinPlaceholder\":\"<pin>\",\n  \"messageText\":\"Your pin is <pin>\",\n  \"pinLength\":4,\n  \"senderId\":\"Infobip 2FA\",\n  \"language\": \"en\",\n  \"repeatDTMF\": \"1#\",\n  \"speechRate\": 1\n}",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Response:

{
    "messageId": "9117FAFA310FFB0259CFBDD2ECD247F2",    
    "applicationId": "797493BB352B7B84588F108CEBAAE43E",
    "name": "Test application BASIC",
    "configuration": {
        "pinAttempts": 10,
        "allowMultiplePinVerifications": true,
        "pinTimeToLive": "15m",
        "verifyPinLimit": "1/3s",
        "sendPinPerApplicationLimit": "10000/1d",
        "sendPinPerPhoneNumberLimit": "3/1d"
    },
    "enabled": true
}
{
  "requestError": {
    "serviceException": {
      "messageId": "INVALID_ARGUMENT",
      "text": "Invalid argument"
    }
  }
}
{
  "requestError": {
    "serviceException": {
      "messageId": "APPLICATION_NOT_FOUND",
      "text": "Application with given id cannot be found."
    }
  }
}
{
  "requestError": {
    "serviceException": {
      "messageId": "THROTTLE_EXCEPTION",
      "text": "Too many requests. Try again later."
    }
  }
}

List all message templates

This method allows you to get all 2FA message templates for a specific application.

GET https://api.infobip.com/2fa/1/applications/{applicationId}/messages

Request example

GET /2fa/1/applications/HJ675435E3A6EA43432G5F37A635KJ8B/messages HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.infobip.com/2fa/1/applications/HJ675435E3A6EA43432G5F37A635KJ8B/messages",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Response:

[
 {
  "messageId": "9C815F8AF3328",
  "applicationId": "HJ675435E3A6EA43432G5F37A635KJ8B",
  "pinPlaceholder": "<pin>",
  "messageText": "Your PIN is <pin>.",
  "pinLength": 4,
  "pinType": "NUMERIC",
  "language": "en",
  "repeatDTMF": "1#",
  "speechRate": 1
 },
 {
  "messageId": "8F0792F86035A",
  "applicationId": "HJ675435E3A6EA43432G5F37A635KJ8B",
  "pinPlaceholder": "<<>>",
  "messageText": "Your PIN is <<>>.",
  "pinLength": 6,
  "pinType": "HEXA",
  "repeatDTMF": "1#",
  "speechRate": 1.5
 }
]
{
  "requestError": {
    "serviceException": {
      "messageId": "MESSAGE_NOT_FOUND",
      "text": "Message with given id cannot be found."
    }
  }
}
{
  "requestError": {
    "serviceException": {
      "messageId": "THROTTLE_EXCEPTION",
      "text": "Too many requests. Try again later."
    }
  }
}

Get a single message template

This method allows you to get a single 2FA message template in specific application.

GET https://api.infobip.com/2fa/1/applications/{applicationId}/messages/{messageId}

Request example

GET /2fa/1/applications/HJ675435E3A6EA43432G5F37A635KJ8B/messages/F66D67327326FCC HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.infobip.com/2fa/1/applications/HJ675435E3A6EA43432G5F37A635KJ8B/messages/F66D67327326FCC",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Response:

{
 "messageId": "F66D67327326FCC",
 "applicationId": "HJ675435E3A6EA43432G5F37A635KJ8B",
 "pinPlaceholder": "<pin>",
 "messageText": "Your pin is <pin>",
 "pinLength": 6,
 "pinType": "ALPHANUMERIC",
 "senderId": "Infobip 2FA",
 "language": "en"
}	
  

Update message template

This method allows you to update a 2FA message template for a specific application.

PUT https://api.infobip.com/2fa/1/applications/{applicationId}/messages/{messageId}

Request example

PUT /2fa/1/applications/HJ675435E3A6EA43432G5F37A635KJ8B/messages/F66D67327326FCC HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json

{
 "pinPlaceholder": "<pin>",
 "messageText": "Your pin is <pin>",
 "pinLength": 6,
 "pinType": "ALPHANUMERIC",
 "senderId": "Infobip 2FA",
 "language": "en",
 "repeatDTMF": "1#",
 "speechRate": 1
}
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.infobip.com/2fa/1/applications/HJ675435E3A6EA43432G5F37A635KJ8B/messages/F66D67327326FCC",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS => "{\r\n  \"pinPlaceholder\": \"<pin>\",\r\n  \"messageText\": \"Your pin is <pin>\",\r\n  \"pinLength\": 6,\r\n  \"pinType\": \"ALPHANUMERIC\",\r\n  \"senderId\": \"Infobip 2FA\",\r\n  \"language\": \"en\",\r\n  \"repeatDTMF\": \"1#\",\r\n  \"speechRate\": 1\r\n}",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Response:

{
 "messageId": "F66D67327326FCC",
 "applicationId": "HJ675435E3A6EA43432G5F37A635KJ8B",
 "pinPlaceholder": "<pin>",
 "messageText": "Your pin is <pin>",
 "pinLength": 6,
 "pinType": "ALPHANUMERIC",
 "senderId": "Infobip 2FA",
 "language": "en",
 "repeatDTMF": "1#",
 "speechRate": 1
}