Viber REST API, how to find Unique Viber user id?

11,846

Solution 1

Danny Dainton mentioned the docs on how you can get data including unique ID about your own account not about somebody else!

You'll receive callbacks containing user unique ID to your webhook if a user subscribes to your public account, and ONLY THEN you'll be able to send message to that user.

As per viber docs:

The send_message API allows accounts to send messages to Viber users who subscribe to the account. Sending a message to a user will be possible only after the user has subscribed to the Public Account by pressing the subscribe button or by sending a message, or by sending a message to a bot (see subscribed callback for additional information).

and VERY IMPORTANT

Before an account can send messages to a user, the user will need to subscribe to the account. Subscribing can take place in one of two ways:

User sends message to the account (both Public Accounts and bots)

  • when a user sends its first message to a account the user will be automatically subscribed to the account. Sending the first message will not trigger a subscribe callback, only a message callback (see receive message from user section). Subscribed event is sent to the Public Account (Public Accounts only)

  • user clicks a subscribe button which triggers the subscribe callback as described below.

Solution 2

Simple, just call the Get Account Info API, whose resource URL is https://chatapi.viber.com/pa/get_account_info You will find the a list of all subscribers in the response along with their user IDs. Please note that these user IDs are unique per user per public account.

Correction: It seems like the Get Account Info API does not return all subscribers, it just returned for me my user ID (the admin of the public account). Based on this, there is no way to get the user IDs of your subscribers other than from the callbacks for new subscribers, messages, ...etc.

Share:
11,846
Admin
Author by

Admin

Updated on June 17, 2022

Comments

  • Admin
    Admin almost 2 years

    Resource URL https://chatapi.viber.com/pa/send_message

    General send message parameters

    enter image description here

    I am trying to send message to viber from Postman. I don't know how to find Unique Viber user id, that parameter is required.

    I am getting this error:

    {"status":999,"status_message":"Bad receiver ID","message_token":5126721184521938239}