Media

Send images, video, audio, voice notes and documents from a URL, and download media you received.

  • POST/v1/sessions/<CHANNEL_ID>/messages/image

    Send an image from a URL.

  • POST/v1/sessions/<CHANNEL_ID>/messages/video

    Send a video from a URL.

  • POST/v1/sessions/<CHANNEL_ID>/messages/audio

    Send an audio file from a URL.

  • POST/v1/sessions/<CHANNEL_ID>/messages/voice

    Send a voice note from a URL.

  • POST/v1/sessions/<CHANNEL_ID>/messages/document

    Send a document from a URL.

  • GET/v1/sessions/<CHANNEL_ID>/media/<MEDIA_ID>

    Download media you received.

Send media

The gateway fetches the file from a URL you give it, uploads it to WhatsApp and sends it. You do not upload bytes to WAgate.

bash
curl -X POST "https://api-wagate.socialground.co/v1/sessions/<CHANNEL_ID>/messages/document" \
  -H "Authorization: Bearer <CHANNEL_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"to": "66XXXXXXXXX", "url": "https://example.com/files/menu.pdf", "caption": "This week'"'"'s menu", "filename": "menu.pdf"}'

The response is the same as for a text: id, chat_jid, timestamp and status: "server_ack".

Fields:

FieldApplies toMeaning
toall, requiredrecipient, as for a text
urlallwhere the file is
captionimage, video, documentup to 4096 UTF-8 bytes. Audio and voice notes carry no caption
filenamedocumentup to 255 UTF-8 bytes, the name the recipient sees. Defaults to the last part of the URL path, then document plus an extension for its type
mime_typedocumentfor example application/pdf. Otherwise the type comes from the URL's Content-Type, else from the bytes

Accepted types and sizes

RouteAcceptedLargest file
imageJPEG, PNG5 MiB
videoMP4 (H.264), 3GPP16 MiB
audioAAC, MP4 audio, MP3, AMR, Ogg. Sent as a file to play, not as a voice note16 MiB
voiceOgg Opus only. Shown as a voice note with its duration16 MiB
documentany file32 MiB

The type is read from the file's bytes, so a wrong file extension or Content-Type does not matter. The one exception is document, where mime_type or the URL's Content-Type is used first.

What the URL must be

  • http or https, with no username or password in it.
  • It must resolve to a public internet address. Every redirect hop is held to the same rule, and it may redirect at most 3 times.
  • It must answer 2xx within 30 seconds.

Errors

Status and codeCauseFix
400 media_type_unsupportedthe file is not a type this kind can carry, for example a WebP sent as an imageconvert it, or send it as a document
400 media_too_largeover the size limit for the kindshrink it, or use document (32 MiB)
400 media_fetch_failedthe URL did not answer, answered with an error, or is not a public addresscheck the URL from outside your network
502 media_upload_failedthe upload to WhatsApp failed and nothing was sentsafe to retry
429 gateway_busy with bound: "media"the gateway is holding as many media sends as it canretry after Retry-After, which is 10 seconds
504 send_unconfirmedoutcome unknown; treat as possibly delivereddo not resend blindly; see Recipes

A media message counts as one message against your daily send cap, and against the sandbox allowance on a sandbox channel, whatever its size.

Download media you received

A message webhook, or a message read from a chat, carries media_id when the message has media. Download it with GET:

bash
curl -o file.bin "https://api-wagate.socialground.co/v1/sessions/<CHANNEL_ID>/media/<MEDIA_ID>" \
  -H "Authorization: Bearer <CHANNEL_TOKEN>"
  • The media ID is 64 hex characters, a dot and an extension.
  • The answer is the file's bytes, not JSON, always served as application/octet-stream as an attachment. Decide the real type from the message's type and the extension.
  • The response carries Cache-Control: private, no-store.
  • A well-formed ID that is not yours always answers 403 media_forbidden, whether it belongs to another channel, does not exist, or was removed by retention. An ID that is not in that shape answers 404 not_found.