Home > Mobile >  Send Images using Whatsapp Cloud Api
Send Images using Whatsapp Cloud Api

Time:05-31

I am trying to send images with Whatsapp Cloud API. Using PHP, I am able to send normal text messages successfully.

When going through the docs, what does 'MEDIA_OBJECT_ID' mean ? An example would be great.

curl -X  POST \
 'https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/messages' \
 -H 'Authorization: Bearer ACCESS_TOKEN' \
 -d '{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "to": "PHONE_NUMBER",
  "type": "image",
  "image": {
    "id" : "MEDIA_OBJECT_ID"
  }
}'

thanks

CodePudding user response:

You need to upload the media to https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/media

The response will give you the "MEDIA_OBJECT_ID"

OR

use image link instead

curl -X  POST \
 'https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/messages' \
 -H 'Authorization: Bearer ACCESS_TOKEN' \
 -d '{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "to": "PHONE_NUMBER",
  "type": "image",
  "image": {
    "link" : "Image URL"
  }
}'

CodePudding user response:

I recommend you to download the WhatsApp Cloud API Postman collection from you Developer Dashboard for future doubts:

  1. Go to https://developers.facebook.com/apps/
  2. Select your WhatsApp application In left sidebar, go to WhatsApp -> Getting Started Click on the button "Run in Postman" to open a full API collection of samples

By the way I recommend you install the PHP SDK for WhatsApp Cloud API:

compose require netflie/whatsapp-cloud-api
  • Related