Homepage

Sending a Binary File Using an API Call Notification

Last edit: Dec 12, 2023

This guide will help you send a file using an API Call Notification.

Requirements

This is an advanced tutorial. To follow it, you should be familiar with basic platformOS concepts, HTML, Liquid, APIs and Forms, and the topics in the Get Started section, especially topics related to Notifications.

Steps

Sending a binary file using an API Call Notification is a special case of creating a regular API Call Notification as described in Get Started: Creating an API Call Notification. This tutorial describes the difference between a regular request and sending a file, so it consists of only one step.

  1. Create API Call Notification

Step 1: Create API Call Notification

app/api_calls/send_file.liquid
---
name: send_file
to: 'https://example.com/endpoint'
format: http
request_type: post_multipart
---
{
  "file": {
    "url": "https://domain.com/my-file.jpg",
    "name": "my-file.jpg",
    "content_type": "image/jpeg"
  },
  "file2": {
    "url": "https://domain.com/other-file.jpg",
    "name": "other-file.jpg",
    "content_type": "image/jpeg"
  }
}

This defines a POST request to the endpoint, which would send two binary files. The main difference between a regular API call and sending a binary file is the _multipart suffix in request type. Valid request types are post_multipart, patch_multipart and put_multipart. The required body format for *_multipart requests is JSON following structure:

{
  "<param name>": {
    "url": "<required url to file remote location>",
    "name": "<optional file name>",
    "content_type": "<optional content type>"
  }
}

Warning

If url includes special characters, for example & [which is the case for private uploads] please make sure to use the html_safe filter.

Questions?

We are always happy to help with any questions you may have.

contact us