Home > Software engineering >  Wrong file type when sending PDF files through Whatsapp API using Postman
Wrong file type when sending PDF files through Whatsapp API using Postman

Time:12-14

I am trying to send a message to myself containing a PDF file stored in Onedrive through Whatsapp API but I am getting the following jpg format:

Message in Whatsapp APP

Oddly enough, when I check Whatsapp Web the same message shows correctly:

Message in Whatsapp Web

What am I doing wrong?

I followed the official documentation and uploaded the media with the following values: values

This returns me the id:

"id": "7054xxxxxxxxxxx"

Finally, I proceed to send the messsage using that same id:

{
    "messaging_product": "whatsapp",
    "to": "{{Recipient-Phone-Number}}",
    "type": "document",
    "document": {
        "id": "7054xxxxxxxxxxx",
        "caption": "Hello, here is today's Daily Report",
        "filename": "dailyreport.pdf"
  }
}

Also, I tried retrieving the media URL and got the following output:

{
    "url": "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=705479771132690&ext=1670800000&hash=ATvvKq-JEv6kn0bW7kq8SXy00yD1BLX_MMbOK-xxxxxx",
    "mime_type": "image/jpeg",
    "sha256": "067e1ac9488efc068dbb1ee4a35ae30c1dec575a70a4dcd77f6cbdc396615912",
    "file_size": 1912582,
    "id": "705479771132690",
    "messaging_product": "whatsapp"
}

I guess "mime_type" should be "application_pdf" instead of "image/jpeg". I have no idea why it would say it is an image.

I am pretty new with this so it may be a simple mistake I am not seeing.

Thank you in advanced for your help!

CodePudding user response:

This is a working example to send a pdf:

curl -X POST 'https://graph.facebook.com/v15.0/<MEDIA_ID>/media' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
-F 'file=@"documents/sales.pdf"' \
-F 'type="application/pdf"' \
-F 'messaging_product="whatsapp"'

You are supposed to set "type" to the media type you're posting.

See details of supported media types, and limitations, here:

https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types

CodePudding user response:

Try setting the header as content-type not just type:

Content-Type: application/pdf
  • Related