File Attachments

You may want to track file attachments alongside your Payables and Receivables, for example, a CSV of the inventory received on a purchase order or a PDF of an invoice. These files will be attached to the invoice record both in Routable and in your integrated accounting software. There is no limit to the number of files attached, but the total size of these files may not exceed 25 megabytes.

File attachments are formatted as Data URLs. We typically recommend a library to help facilitate the process of creating these URLs. Here's a few snippets to get you started:

from datauri import DataURI
const attachment_for_routable_api = { 
   # => data:application/pdf;base64,JVBERi0xLjMNJeLjz9 (truncated)
   "data_uri": str(DataURI.from_file('test.pdf')) 
   "name": "test.pdf"
}
const Datauri = require('datauri/sync');

const attachment_for_routable_api = { 
   //  data:application/pdf;base64,JVBE Ri0xLjMNJ (truncated)
   "data_uri": Datauri('test.pdf').content,  
   "name": "test.pdf"
}
$filename = 'test.pdf';
$mime_type = mime_content_type($filename)
$data = file_get_contents($filename);
$attachment_for_routable_api = { 
   // data:application/pdf;base64,JVBE Ri0xLjMNJ (truncated)
   "data_uri": 'data:' . $mime_type . ';base64,' . base64_encode($data),
   "name": $filename
}

We currently support attaching the following file types:

  • CSV
  • DOCX
  • JPG
  • PDF
  • PNG
  • TXT
  • XLSX

❗️

Be extra careful with file attachments uploaded from users!

Certain file formats such as DOCX and PDF can carry hidden malware. If your application is allowing file uploads from end users, you should absolutely perform rigorous validation against those files to ensure they are safe to be processed before allowing them to be processed by your system or by Routable. Techniques for doing this in various programming languages are outside the scope of this document.

To attach the Data URI to a Payable or Receivable, add an Attachment object in the attachments array of the Create a Payable or Create a Receivable request:

{ 
    "data_uri": "data:application/pdf;base64,JVBERi0xLjMNJeLjz9...",
    "name": "filename_to_save_as_on_Routable.pdf"
}

What’s Next