Two-Factor Authentication with Messaging

Two-Factor authentication with Bandwidth Messaging services

⚠️ Your account must be activated to use the MFA product. Please contact sales support to learn how to get access!

Request URL


Basic Authentication

Bandwidth's Voice API leverages Basic Authentication with your Dashboard API Credentials. Read more about how Bandwidth secures endpoints in the Security & Credentials document.

Supported Parameters

Parameter Required Description
to Yes To telephone number
from Yes From telephone number
applicationId Yes The messaging application id
scope No An optional field to denote what scope or action the 2fa code is addressing. If not supplied, defaults to "2FA".
message Yes The message format of the 2fa code. There are three values that the system will replace "{CODE}", "{NAME}", "{SCOPE}". The "{SCOPE}" and "{NAME} value template are optional, while "{CODE}" must be supplied. As the name would suggest, code will be replace with the actual 2fa code. Name is replaced with the application name, configured during provisioning of 2fa. The scope value is the same value sent during the call and partitioned by the server.
digits Yes The number of digits for your 2fa code. The valid number ranges from 2 to 8, inclusively.

Response Attributes

Property Description
MessageId The Message Id

Example 1 of 1: Authenticate with Messaging

curl -X POST \
    --url "{accountId}/code/messaging" \
    -u '{username}:{password}' \
    --data-raw '
        "to"            : "+12345678902",
        "from"          : "+12345678901",
        "applicationId" : "93de2206-9669-4e07-948d-329f4b722ee2",
        "scope"         : "scope",
        "digits"        : 5,
        "message"       : "Your temporary {NAME} {SCOPE} code is {CODE}"

The above command returns a JSON Response structured like this:

Status: 200
Content-Type: application/json; charset=utf-8

  "MessageId": "1256-adf14asd-52dfa"
var response = controller.CreateMessagingTwoFactor(accountId, new TwoFactorCodeRequestSchema
    ApplicationId = applicationId,
    From = fromNumber,
    To = toNumber,
    Scope = "scope",
    Digits = 5,
    Message = "Your temporary {NAME} {SCOPE} code is {CODE}"

Console.WriteLine( response.Data.MessageId );
TwoFactorCodeRequestSchema request = new TwoFactorCodeRequestSchema();
request.setMessage("Your temporary {NAME} {SCOPE} code is {CODE}");

ApiResponse<TwoFactorMessagingResponse> response = controller.createMessagingTwoFactor(accountId, request);

System.out.println( response.getResult().getMessageId() );
application_id = messaging_application_id

body =
body.from = from_phone = to_phone
body.application_id = application_id
body.scope = 'scope'
body.digits = 5
body.message = "Your temporary {NAME} {SCOPE} code is {CODE}"

auth_client.create_messaging_two_factor(account_id, body)
application_id = messaging_application_id
body = TwoFactorCodeRequestSchema(
    mfrom = from_phone,
    to = to_phone,
    application_id = messaging_application_id,
    scope = 'scope',
    digits = 5,
    message = "Your temporary {NAME} {SCOPE} code is {CODE}"
response = auth_client.create_messaging_two_factor(account_id, body)
message_id = response.body.message_id
const payload = new mfa.TwoFactorCodeRequestSchema();
payload.applicationId = applicationId;
payload.from = fromNumber; = toNumber;
payload.scope = 'scope';
payload.digits = 5;
payload.message = "Your temporary {NAME} {SCOPE} code is {CODE}";

const response = await controller.createMessagingTwoFactor(accountId, payload);

console.log(JSON.stringify(response, null, 2));
$scope = 'scope';

$body = new BandwidthLib\TwoFactorAuth\Models\TwoFactorCodeRequestSchema();
$body->from = $fromPhone;
$body->to = $toPhone;
$body->applicationId = $messagingApplicationId;
$body->scope = $scope;
$body->digits = 5;
$body->message = "Your temporary {NAME} {SCOPE} code is {CODE}";

$authClient->createMessagingTwoFactor($accountId, $body);

results matching ""

    No results matching ""