Viber REST API, how to find Unique Viber user id?
Asked Answered
E

3

6

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}

Ethelethelbert answered 27/12, 2017 at 8:30 Comment(1)
share your codeDogberry
S
7

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.

Schade answered 26/1, 2018 at 9:9 Comment(2)
What if the account already has a good number of subscribers, how to get IDs of already subscribed users?Vernice
if we like send bulk message so how to we do this >? number is new and generated by code for send message . i try send message but alway i see this messageDavidadavidde
S
3

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.

Screech answered 11/9, 2019 at 22:35 Comment(0)
B
0

Normally you should collect Viber IDs from all callbacks and store in DB for future use. But if you missed that step you can collect Viber IDs of online subscribed users by periodic call to get_online endpoint and then use get_user_details endpoint to get more info about unknown ones.

Bedstraw answered 3/12, 2019 at 12:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.