Search code examples
postmancloudwhatsapp

Whatsapp Cloud API Update Profile Picture


I'm trying to upload an image as profile picture using WhatsApp Cloud API *.

After creating an application using WhatsApp Cloud API I'm not allowed to access neither using the regular application nor using Business Application. It says something like "try again in one hour". So I have to implement everything using the API.

After reading the docs and importing Postman Endpoints I found the one called Business Profiles > Update Business Profile

https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile

It has a field "profile_picture_url"and I have tried POSTing media https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/media and then with the given ID y used https://graph.facebook.com/{{Version}}/{{Media-ID}} to get the URL but it didn't work. The rest of the information is updated successfully

{
    "messaging_product": "whatsapp",
    "address": "",
    "description": "Simple Bot",
    "email": "[email protected]",
    "websites": [
        "https://..."
    ],
    "profile_picture_url": "https://lookaside.fbsbx.com/..."
}

However if I try to send someone using the ID and the endpoint https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/messages it works fine. And if I use Download Media Content with the URL in Postman it works fine too.

I don't know if I have misunderstood something or if it can't be done using the API.


Solution

  • It is mentioned in the Cloud API Documentation:

    profile_picture_url (Optional): URL of the profile picture generated from a call to the Resumable Upload API.

    But, i got it working using profile_picture_handle instead of profile_picture_url. So how do we get the profile_picture_handle?

    Prerequisite:

    1. Graph API token here. Or use your WhatsApp Cloud API token.
    2. App ID, go Apps > Your App > Settings (sidebar menu) > Basic

    Update Photo Profile:

    1. Call POST https://graph.facebook.com/v14.0/{{appId}}/uploads?access_token={{token}}&file_length={{fileSizeInByte}}&file_type=image/jpeg
    2. Save the session id you got, upload:XXXXXX?sig=XXXXXX.
    3. Call POST https://graph.facebook.com/v14.0/{{sessionId}}, with the headers: Authorization=OAuth {{token}}, file_offset=0, Host=graph.facebook.com, Connection=close, Content-Type=multipart/form-data, and include your image file in the request body with type binary. If you using Postman, see image below (This is what I missed for hours). enter image description here
    4. Save the handle result you got, 4::XXX==:XXXXXX.
    5. Finally, call POST https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile, with json request body: {"messaging_product": "whatsapp", "profile_picture_handle": "4::XXX==:XXXXXX"}

    That's it, You can check the profile picture.