One-time code by Viber, with SMS as a fallback
Send a one-time code in Viber, and send it by SMS when Viber does not reach the phone.With Viber you make the code yourself and you check it yourself; the API delivers it. All Viber calls take the
API key in a header named apiId.1
Find your sender and a code template (once)
2
Send the code
Send a Viber one-time code:
{"data": [{"succeeded": true, "ids": [1043], "strIds": null, "errors": null}]}
Keep data[0].ids[0]: it is the id of this send. A 200 answer means the send was processed, not that the
message reached the phone. A refusal answers 400 with the reason, for example Sender is not found or
Insufficient balance. 3
See whether it arrived
Ask for the record of the send with
List Viber message records, filtering
campaignId by
the id you kept:
status | Meaning | What to do |
|---|
Delivered or Seen | The code is on the phone. | Wait for the person to type it. |
SendFailed | The send was refused. | Send by SMS now. |
Expired | It was not delivered in time. | Send by SMS now. |
4
Fall back to SMS
If the record is not
Delivered or
Seen after a wait you choose (20 to 30 seconds is common), send the same
code by SMS with
Send SMS and
sms_type set to
T. Use the same code, so that whichever
message arrives first works.
Want the fallback done for you? Create a campaign with two channels, Viber first and SMS second
(Create a campaign). Each recipient gets the message on the first channel that can reach
them. A campaign starts at the next 5-minute mark, so use it for notifications, not for sign-in codes that
must arrive in seconds. Modified at 2026-10-08 11:07:10