Developer Docs

Table of contents

2FA API

BSG 2FA API is a RESTful API for two-factor user authentication on a website or web application: you can use it to confirm a transaction, and user contact information, as a second factor in user authentication, and more.

BSG 2FA API provides a choice of channel for sending a one-time password (OTP) to a user: SMS or Viber. Connect the channel you need in your personal account on the “Settings” page of the “2FA” section and start working with the BSG 2FA API.

Please note: 2FA API is not available for use in DEMO and TEST account modes (modes in which your account data is not verified). 

Make sure that you have entered all the necessary data in your account settings in order to use the 2FA service.

Available HTTP Methods

  1. Send a one-time password;
  2. Resend the one-time code;
  3. Check the one-time Code;
  4. Cancel the authentication session;
  5. Check authentication status;
  6. Get a list of authentication sessions.

Send One-time password

This API call is used to generate and send a one-time password to a user in an SMS or Viber message. Please note: authentication of recipients who are in the SMS or Viber stop list in your contact book is not possible using the corresponding method. (That is, if the recipient is in the SMS stop list, then when requesting authentication using the SMS method, the one-time password will not be sent, and you will receive an error in response).

To send One-time password make a request to this URL:

POST      https://one-api.bsg.world/api/2fa/authentications/otp

Request parameters

ParameterRequiresTypeDefaultDescription
channelYesstringNoA channel for sending a one-time password. Possible values: “SMS”, “Viber”.
senderYesstringNoSender’s name:from 3 to 11 characters for the sender’s alphanumeric name (Latin letters, symbols, numbers, spaces);3 to 15 characters for the sender’s numeric name.
recipientYesintegerNoThe phone number of the recipient of the one-time password. 9 to 15 digits without the + sign. 3 to 15 characters for the sender’s numeric name.
message_textYesstringNoMessage text. Must necessarily include a variable for the password in the form — {code}. When a message is sent, the variable is replaced with a one-time password.The maximum length of the message text, including the number of characters for the password:For SMS: up to 70 characters for Cyrillic, up to 160 characters for Latin;For Viber: up to 1000 characters.
code_digitsYesintegerNoThe length of the numeric code, from 3 to 9 digits.
code_lifetimeYesintegerNoThe password expiration time after which the password becomes invalid. An integer from 30 seconds to 300 seconds.
code_max_triesYesintegerNoThe number of password verification attempts.An integer from 1 to 5.
sender_altNostringNoUsed only for the Viber channel to alternatively send a one-time code in SMS (if it was not possible to send the code in a Viber message, for example, if the recipient is not a Viber user).The name or number of the SMS sender. String up to 15 characters:from 3 to 11 characters for the sender’s alphanumeric name (Latin letters, symbols, numbers, spaces);3 to 15 characters for the sender’s numeric name.
message_alt_textNostringNoThe text of the SMS message. Must necessarily include a variable for the password in the form — {code}. The variable will be replaced with a one-time password when the message is sent.Maximum message length, including the number of characters for the code:for Cyrillic – 70 characters;for Latin – 160.This parameter is set only if Viber is selected as the channel for sending the code.Used to alternatively send a one-time password in an SMS message (if it was not possible to send the password in a Viber message, for example, if the recipient is not a Viber user).

Request example

{
  "recipient": "61401629754",
  "channel": "string",
  "sender": "SENDER",
  "sender_alt": "SENDER_ALT",
  "message_text": "Your verification code: {code}",
  "message_alt_text": "Your alternative code: {code}",
  "code_lifetime": 300,
  "code_max_tries": 3,
  "code_digits": 5
}

Response parameters

ParameterTypeDescription
idstringThe ID of the generated authentication.
recipientstringNumber of the recipient of the message with a one-time code.
statusstringAuthentication status. Possible values: pending (authentication session successfully created and pending).
channelstringAuthentication channel selected for sending the one-time code
senderstringSender name.
sender_altstring/nullSMS sender name.
message_textstringMessage text.
message_alt_textstring/nullThe text for the SMS. 
code_lifetimeintegerOTP expiration date.
code_max_triesintegerThe number of OTP check attempts.
code_digitsintegerThe number of digits in the OTP.
pricefloatAuthentication cost. At the time of creating the authentication, 0 is indicated.
currencystringThe three-letter code of the currency in which the value is indicated. Corresponds to the user’s account currency. 
country_codestringThe country code of the recipient of the one-time password according to the ISO 3166-1 alpha-2 standard.
expired_atstringDate and time when the authentication expires in ISO 8601 format.
created_atstringThe date and time of the authentication session were created in ISO 8601 format.
finished_atnullDate and time when the authentication session was closed. At the time of creating the authentication, the value “null” is indicated.

Response example

Response in case of successful request:

{
  "data": {
    "id": "bf4381c8-9d4a-4705-bd28-f89a830b7f96",
    "recipient": "380979965073",
    "status": "pending",
    "channel": "sms",
    "sender": "SENDER",
    "sender_alt": "SENDER_ALT",
    "message_text": "Your verification code: {code}",
    "message_alt_text": "Your alternative code: {code}",
    "code_lifetime": 300,
    "code_max_tries": 3,
    "code_digits": 5,
    "price": "0,02",
    "currency": "USD",
    "country_code": "UA",
    "expired_at": "2023-01-04 18:37:06",
    "created_at": "2023-01-04 17:37:06"
    "finished_at": "2023-01-04 17:37:06"
  }
}

Resend the one-time code

Used to resend the one-time password to the recipient: a new one-time password is generated and sent in the message, and the previous one becomes invalid. When resending, already saved data is used to generate the OTP from the request https://one-api.bsg.world/api/2fa/authentications/otp 

This API call is available only if the current authentication is not completed before its expiration date (the authentication validity period is specified in each 2FA API response).

To resend the one-time code send request to this URL:

POST      https://one-api.bsg.world/api/2fa/authentications/otp/{id}/resend

Request parameters

ParameterRequiresTypeDefaultDescription
idYesstringNoAuthentication ID received in response to https://one-api.bsg.world/api/2fa/authentications/otp The maximum length is 36 characters.

Response parameters

ParameterTypeDescription
idstringThe ID of the generated authentication.
recipientstringNumber of the recipient of the message with a one-time code.
statusstringAuthentication status. Possible values: pending (authentication session successfully created and pending).
channelstringAuthentication channel selected for sending the one-time code
senderstringSender name.
sender_altstring/nullSMS sender name.
message_textstringMessage text.
message_alt_textstring/nullThe text for the SMS. 
code_lifetimeintegerOTP expiration date.
code_max_triesintegerThe number of OTP check attempts.
code_digitsintegerThe number of digits in the OTP.
pricefloatAuthentication cost. At the time of creating the authentication, 0 is indicated.
currencystringThe three-letter code of the currency in which the value is indicated. Corresponds to the user’s account currency. 
country_codestringThe country code of the recipient of the one-time password according to the ISO 3166-1 alpha-2 standard.
expired_atstringDate and time when the authentication expires in ISO 8601 format.
created_atstringThe date and time of the authentication session were created in ISO 8601 format.
finished_atnullDate and time when the authentication session was closed. At the time of creating the authentication, the value “null” is indicated.

Response example

Response in case of successful request:

{
  "data": {
    "id": "bf4381c8-9d4a-4705-bd28-f89a830b7f96",
    "recipient": "380979965073",
    "status": "pending",
    "channel": "sms",
    "sender": "SENDER",
    "sender_alt": "SENDER_ALT",
    "message_text": "Your verification code: {code}",
    "message_alt_text": "Your alternative code: {code}",
    "code_lifetime": 300,
    "code_max_tries": 3,
    "code_digits": 5,
    "price": "0,02",
    "currency": "USD",
    "country_code": "UA",
    "expired_at": "2023-01-04 18:37:06",
    "created_at": "2023-01-04 17:37:06"
    "finished_at": "2023-01-04 17:37:06"
  }
}

Check one-time Code

The API call is used to verify that the one-time password you received from the user matches the one sent by BSG.

To Check one-time Code send request to this URL:

POST      https://one-api.bsg.world/api/2fa/authentications/otp/{id}/verify

Request parameters

ParameterRequiresTypeDefaultDescription
idYesstringNoAuthentication ID received in response to https://one-api.bsg.world/api/2fa/authentications/otp The maximum length is 36 characters.
access_code YesintegerNoThe one-time password received by the user through the specified channel or alternative channel (optional) in the generation request that needs to be validated.An integer from 3 to 9 digits.

Response parameters

An example of a response if the code is incorrect:

{
  "errors": [
    {
      "message": "The code does not match the expected value"
    }
  ]
}

If the one-time code is correct:

ParameterTypeDescription
idstringThe ID of the generated authentication.
recipientstringNumber of the recipient of the message with a one-time password.
statusstringAuthentication status. Possible values: verified (the code was successfully verified, and the session was closed with a successful result).
channelstringChannel for authentication.
senderstringSender name.
sender_altstringSMS sender name.
message_textstringMessage text.
message_alt_textstringThe text for the SMS. 
code_lifetimeintegerOTP expiration date.
code_max_triesintegerThe number of OTP check attempts.
code_digitsintegerThe number of digits in the OTP.
pricefloatAuthentication cost (excluding the cost of sent messages).
currencystringThe three-letter code of the currency in which the value is indicated. Corresponds to the user’s account currency.
country_codestringReceiver’s country code according to ISO 3166-1 alpha-2.
expired_atstringDate and time when the authentication session expires in ISO 8601 format.
created_atstringThe date and time of the authentication session were created in ISO 8601 format.
finished_atstringDate and time when the authentication session was closed in ISO 8601 format.

Response example

{
  "data": {
    "id": "bf4381c8-9d4a-4705-bd28-f89a830b7f96",
    "recipient": "380979965073",
    "status": "pending",
    "channel": "sms",
    "sender": "SENDER",
    "sender_alt": "SENDER_ALT",
    "message_text": "Your verification code: {code}",
    "message_alt_text": "Your alternative code: {code}",
    "code_lifetime": 300,
    "code_max_tries": 3,
    "code_digits": 5,
    "price": "0,02",
    "currency": "USD",
    "country_code": "UA",
    "expired_at": "2023-01-04 18:37:06",
    "created_at": "2023-01-04 17:37:06"
    "finished_at": "2023-01-04 17:37:06"
  }
}

Cancel the authentication session

Used to cancel the authentication process. In this case, authentication must be in the Pending status.

To cancel the authentication session send request to this URL:

POST      https://one-api.bsg.world/api/2fa/authentications/{id}/cancel

Request parameters

ParametersRequiresTypeDefaultDescription
idYesstringNoAuthentication ID received in response to https://one-api.bsg.world/api/2fa/authentications/otp The maximum length is 36 characters.

Response parameters

ParameterTypeDescription
idstringThe ID of the generated authentication.
recipientstringNumber of the recipient of the message with the OTP code.
statusstringAuthentication status. Possible values: canceled.
channelstringChannel for authentication.
senderstringSender’s name.
sender_altstringAlternate SMS sender name
message_textstringMessage text.
message_alt_textstringAlternative text for SMS message
code_lifetimeintegerOTP expiration date.
code_max_triesintegerThe number of OTP check attempts.
code_digitsintegerThe number of digits in the OTP.
pricefloatAuthentication session cost. If authentication is canceled, the cost will be 0.
currencystringThe three-letter code of the currency in which the cost is indicated. 
country_codestringReceiver’s country code according to ISO 3166-1 alpha-2.
expired_atstringDate and time when the authentication session expires in ISO 8601 format.
created_atstringThe date and time of the authentication session was created in ISO 8601 format.
finished_atstringDate and time when the authentication session was closed in ISO 8601 format. 

Response example

Response in case of successful request:

{
  "data": {
    "id": "bf4381c8-9d4a-4705-bd28-f89a830b7f96",
    "recipient": "380979965073",
    "status": "canceled",
    "channel": "sms",
    "sender": "SENDER",
    "sender_alt": "SENDER_ALT",
    "message_text": "Your verification code: {code}",
    "message_alt_text": "Your alternative code: {code}",
    "code_lifetime": 300,
    "code_max_tries": 3,
    "code_digits": 5,
    "price": "0,02",
    "currency": "USD",
    "country_code": "UA",
    "expired_at": "2023-01-04 18:37:06",
    "created_at": "2023-01-04 17:37:06"
    "finished_at": "2023-01-04 17:37:06"
  }
}

Check authentication status

Use to get information about the current authentication status by specifying its identifier.

To check authentication status send request to this URL:

GET     https://one-api.bsg.world/api/2fa/authentications/{id}

Request parameters

ParameterRequiresTypeDefaultDescription
idYesstringNoAuthentication ID received in response to https://one-api.bsg.world/api/2fa/authentications/otp. The maximum length is 36 characters.

Response parameters

ParameterTypeDescription
idstringAuthentication ID created at the request of the user.
recipientstringOTP message recipient number (specified by the user in the authentication request)
statusstringAuthentication status. Possible values:pending – authentication has been created and is in the pending state;verified – authentication successful (code successfully verified);expired – authentication has expired;failed – authentication failed;canceled – authentication has been canceled.
channelstringAuthentication channel. Possible values: SMS, Viber.
senderstringThe name of the sender (specified by the user in the authentication request).
sender_altstringAlternative sender name for sending SMS (specified by the user in the authentication request).
message_textstringMessage text (specified by the user in the authentication request).
message_alt_textstringAlternate text for the message (specified by the user in the authentication request).
code_lifetimeintegerOTP expiration date (specified by the user in the authentication request).
code_max_triesintegerNumber of OTP verification attempts (specified by the user in the authentication request).
code_digitsintegerThe number of digits in the OTP (specified by the user in the authentication request).
pricestringAuthentication cost (excluding the cost of sent messages). The amount must be displayed with 7 decimal places.
currencystringThe three-letter code of the currency in which the value is indicated.
country_codestringReceiver’s country code according to ISO 3166-1 alpha-2.
expired_atstringThe expiration date of the authentication session.
created_atstringThe date and time of the authentication were created in ISO 8601 format.
finished_atstringDate and time when authentication was closed in ISO 8601 format.
messagesarrayArray of message objects:
messages[]idstringThe unique ID of the message.
messages[]recipientstringThe recipient’s phone number.
messages[]statusstringMessage status. Possible values:delivered – the message was sent;accepted – message accepted for sending;undelivered – the message was not delivered.
messages[]channelstringThe channel for sending the message. Possible values: SMS or Viber.
messages[]senderstringThe name of the sender of the message.
messages[]textstringMessage text.
messages[]pricefloatMessage cost.
messages[]currencystringThe three-letter code of the currency in which the value is indicated.
messages[]sent_atstringThe date and time of the message were sent in ISO 8601 format.
messages[]created_atstringThe date and time the message was created in ISO 8601 format.

Response example

Response in case of successful request:

{
  "data": {
      "id": "ea5db413-e368-4952-b745-cc2030210c49",
      "recipient": "380501403813",
      "status": "verified",
      "channel": "sms",
      "sender": "testsms",
      "sender_alt": "string",
     "message_text": "Your BSG 2FA confirmation code is {code}. Do not share this with anyone else.",
      "message_alt_text": "string",
      "code_lifetime": 30,
      "code_max_tries": 5,
      "code_digits": 6,
      "price": 50.25,
      "currency": "EUR",
      "country_code": "FR",
      "expired_at": "2022-04-28 14:21:16",
      "created_at": "2022-04-28 14:21:16",
      "updated_at": "2022-04-28 14:21:16",
      "finished_at": "2022-04-28 14:21:16",
      "messages": [
        {
          "id": "1ed32701-5d4f-6cfa-ba06-9db3aa8bab68",
          "recipient": "61401629754",
          "status": "accepted",
          "channel": "sms",
          "sender": "SENDER",
          "text": "Your verification code: {code}",
          "price": 0.0642918,
          "currency": "EUR",
          "sent_at": "2022-04-18 11:00:30",
          "created_at": "2022-04-18 10:55:35"
        }
      ]
  }
}

Get a list of authentication sessions

Use to get a list of authentications for a period.

To get a list of authentication sessions make a request to this URL:

GET     https://one-api.bsg.world/api/2fa/authentications

Request parameters

ParameterRequiresTypeDefaultDescription
page[offset]Nointeger0Get auths starting at offset.
page[limit]Nointeger10The number of authentications in the response. Possible values are from 10 to 500.
filter[from]YesstringPeriod start date (date and time when the authentication session was created) in ISO 8601 format.
filter[to]YesstringEnd date of the period (date and time when the authentication was created) in ISO 8601 format.
filter[ids]NostringAuthentication ID. The maximum number is 3.
filter[status]NostringPossible values: “pending”, “verified”, “expired”, “failed”, “canceled”.
filter[channel]NostringPossible values: “SMS”, “Viber”.
filter[recipient]NostringThe phone number to which you want to send the OTP code. 9 to 15 digits.
filter[country_code]NostringBeneficiary country code according to ISO 3166-1 alpha-2
wayNostringascSort options: asc, desc
sortNostringcreated_atSort by: id, status, channel, recipient, created_at, finished_at, country_code.

Response parameters

ParameterTypeDescription
listarrayAn array of authentication objects.
list[]idstringThe ID of the generated authentication.
list[]recipientstringNumber of the recipient of the message with the OTP code.
list[]statusstringAuthentication status. Possible values:pending – authentication has been created and is in the pending state;verified – authentication successful (one-time password successfully verified);expired – authentication has expired;failed – authentication failed;canceled – authentication has been canceled.
list[]channelstringChannel for authentication.
list[]senderstringSender’s name.
list[]sender_altstringAlternative sender name for SMS.
list[]message_textstringMessage text.
list[]message_alt_textstringAlternative text for the SMS message.
list[]code_lifetimeintegerThe expiration date of the one-time password.
list[]code_max_triesintegerThe number of attempts to verify the one-time password.
list[]code_digitsintegerThe number of digits in the one-time password.
list[]pricefloatAuthentication session cost. 
list[]currencystringThe three-letter code of the currency in which the authentication cost is indicated.
list[]country_codestringReceiver’s country code according to ISO 3166-1 alpha-2.
list[]expired_atstringThe expiration date of the authentication in ISO 8601 format.
list[]created_atstringThe date and time of the authentication was created in ISO 8601 format.
list[]finished_atstringDate and time when authentication was closed in ISO 8601 format.
list[]messagesarrayArray of message objects:
list[]messages[]idstringThe unique ID of the message.
list[]messages[]recipientstringThe recipient’s phone number.
list[]messages[]statusstringMessage status. Possible values:delivered – the message was sent;accepted – message accepted for sending;undelivered – the message was not delivered.
list[]messages[]senderstringThe name of the sender of the message.
list[]messages[]textstringMessage text.
list[]messages[]pricefloatMessage cost.
list[]messages[]currencystringCurrency of the account in which the cost is indicated. Corresponds to the user’s account currency.
list[]messages[]sent_atstringThe date and time of the message was sent in ISO 8601 format.
list[]messages[]created_atstringThe date and time the message was created in ISO 8601 format.
totalintegerThe total number of authentications.

Response example

Response in case of successful request:

{
  "data": {
    "list": [
      {
      "id": "ea5db413-e368-4952-b745-cc2030210c49",
      "recipient": "380501403813",
      "status": "verified",
      "channel": "sms",
      "sender": "testsms",
      "sender_alt": "string",
     "message_text": "Your BSG 2FA confirmation code is {code}. Do not share this with anyone else.",
      "message_alt_text": "string",
      "code_lifetime": 30,
      "code_max_tries": 5,
      "code_digits": 6,
      "price": 50.25,
      "currency": "EUR",
      "country_code": "FR",
      "expired_at": "2022-04-28 14:21:16",
      "created_at": "2022-04-28 14:21:16",
      "updated_at": "2022-04-28 14:21:16",
      "finished_at": "2022-04-28 14:21:16",
      "messages": [
        {
          "id": "1ed32701-5d4f-6cfa-ba06-9db3aa8bab68",
          "recipient": "61401629754",
          "status": "accepted",
          "channel": "sms",
          "sender": "SENDER",
          "text": "Your verification code: {code}",
          "price": 0.0642918,
          "currency": "EUR",
          "sent_at": "2022-04-18 11:00:30",
          "created_at": "2022-04-18 10:55:35"
        }
      ]
    },
    "total": 100
  }
}

2FA errors:

One API errors responses:

    1.1. Access code expired

    1.2. Access code not found

    1.3. Authentication canceled status

    1.4. Authentication expired

    1.5. Authentication failed status

    1.6. Authentication invalid status

    1.7. Authentication limit with status pending

    1.8. Total authentication limit

    1.9. Authentication verifying attempts limit

    1.10. Authentication not found

    1.11. Authentication price not found

    1.12. Insufficient funds

    1.13. Recipient exists on the stop list

    1.14. Authentication channel inactive

    1.15. Authentication channel not found

{
  "errors": [
    {
      "message": "ERROR_MESSAGE_1"
    }
  ]
}

2. OneAPI validation errors:

{
  "message": "The given data was invalid.",
  "errors": {
    "<FIELD_1>": [
      "<VALIDATION_ERROR_1>"
    ], ...

    "<FIELD_N>": [
      "<VALIDATION_ERROR_N>"
    ]
  }
}

3. OneAPI to 2FA integration errors:

    3.1. Raw error 2FA Service response is empty.

    3.2. Raw error 2FA Service response has an incorrect content.

    3.3. Error 2FA Service response is empty.

    3.4. Error 2FA Service response structure is incorrect.

    3.5. 2FA Service getting error response error.

    3.6. 2FA Service getting successful response error.

    3.7. 2FA Service getting response error.

    3.8. 2FA Service error.

    3.9. 2FA Service getting error response error.

    3.10. 2FA Service getting successful response error.

    3.11. 2FA Service getting response error.

{
  "message": "<ERROR_MESSAGE>",
  "errors": [
    ...
  ]
}

We use cookies (and other similar technologies) to collect data to improve your experience on our site. By using our website, you’re agreeing to the collection of data as described in our Website Data Collection Policy.