All messaging endpoints support sending attachments. You can include either one or multiple attachments in one of two formats:

  1. HTTPS URL: We’ll download the attachment from the provided URL. This is the easiest method, but requires you to serve your files over the internet.

  2. Media Library URI: Use this feature when you need to upload files directly using the media_library:// protocol.

Using the Media Library

First, create a signed upload URL with the path to your file:

const response = await api.request(
  `/storage/upload/sign/media_library/test.png`,
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${API_KEY}`,
    },
  }
);

const url = await response.text();

The file will be uploaded to test.png.

You can also upload to nested paths, for example /storage/upload/sign/media_library/my-dir/test.png. This will create an upload URL for my-dir/test.png.

Next, upload your file using the signed URL:

const res = await fetch(url, {
  method: 'PUT',
  body: Buffer.from(BASE_64_IMAGE, 'base64'),
  headers: { 'Content-Type': 'image/png' },
});

Media library files are automatically deleted after 30 days. Until then, you can use them as often as needed when sending messages or broadcasts by passing them as attachments:

  • attachments: ["media_library://test.png"]
  • attachments: ["media_library://my-dir/test.png"]