Get a profile picture of a chat or user

Explore this if you need to know about contact and chat avatars

Get a contact image or chat/group picture

Very often developers and businesses need to retrieve details about a contact, including a profile image. It is quite easy to do it via API. To get chat or profile images in requests such as Get Chats, Get Contacts, Get Messages, you need to enable the init_avatars setting in the channel and re-authorize.

curl --request PATCH \
     --url https://gate.whapi.cloud/settings \
     --header 'accept: application/json' \
     --header 'authorization: Bearer {your_token}' \
     --header 'content-type: application/json' \
     --data '
{
  "media": {
    "init_avatars": true
  }
}
'

Setting init_avatars: true allows you to get chat avatars after channel authorization. Thus, you will need to reconnect to the channel again. Or set this setting before connecting. This setting requires only one-time activation and the channel remembers this setting.

Why is it done this way?

The fact is that uploading contacts and handling profile pictures for WhatsApp is a massive activity, as you are actively getting to know many contacts in a short period of time. To reduce the risks for new fresh numbers, we decided to introduce this setting.

This way, you will be out of risk when you connect. However, if your number is already stable with the API, you can safely automatically get profile images of all contacts and chats using this setting.

How to get a profile pic if the user is not in your Contacts List

The previous setting is only relevant for chats that are present in your app. However, you can also get this information about any contact outside of your phonebook and without corresponding with them. The cell phone user is not made aware of this!

curl --request GET \
     --url https://gate.whapi.cloud/contacts/919984351847/profile \
     --header 'accept: application/json' \
     --header 'authorization: Bearer {your_token}'

Last updated