Developing on Invoiced
File Attachments
5min
invoiced supports attaching files to invoices to give customers more context about a bill usage files can be attached to invoices through the dashboard or programmatically through the api in this guide, we will walk you through the complete steps to attach a file to an invoice through the api 1\ create a file you can upload a file using our api or host your file somewhere publicly accessible to upload a local file, make the following request curl https //api invoiced com/files \\ u {api key} \\ h "content type\ multipart/form data" \\ f "file=@/path/to/your/file/yourfilename pdf" \\ f "name=file" if your file is publicly hosted, make this request instead curl "https //api invoiced com/files" \\ u {api key} \\ d url="https //www invoiced com/img/logo invoice png" \\ d name="logo invoice png" \ # filename d size=6936 \ # size in bytes d type="image/png" # mime typeimport com invoiced entity connection; import com invoiced entity file; connection invoiced = new connection("{your api key}", false); file file = invoiced newfile(); file url = "https //www invoiced com/img/logo invoice png"; file size = 6936; file name = "logo invoice png"; file type = "image/png"; file create();\<?php $invoiced = new invoiced\client("{your api key}"); $file = $invoiced >file >create(\[ 'url' => "https //www invoiced com/img/logo invoice png", 'name' => "logo invoice png", // filename 'size' => 6936, // size in bytes 'type' => "image/png" // mime type ]);import invoiced client = invoiced client("{your api key}") file = client file create( url="https //www invoiced com/img/logo invoice png", name="logo invoice png", # filename size=6936, # size in bytes type="image/png" # mime type )require "invoiced" invoiced = invoiced client new("{your api key}") file = invoiced file create( \ url => "https //www invoiced com/img/logo invoice png", \ name => "logo invoice png", # filename \ size => 6936, # size in bytes \ type => "image/png" # mime type ) 2\ attach to an invoice once you have created your file, you can attach it to an invoice this is done by passing in an array of file ids through the attachments parameter when creating or editing an invoice in this example, we are going to show how to attach a single file when creating a new invoice curl "https //api invoiced com/invoices" \\ u {api key} \\ \# invoice parameters d attachments\[]={file id}import com invoiced entity attachment; import com invoiced entity invoice; invoice invoice = invoiced newinvoice(); // invoice parameters attachment\[] attachments = new attachment\[1]; attachments\[0] = new attachment(); attachments\[0] file = file id; invoice attachments = attachments; invoice create();\<?php $invoiced >invoice >create(\[ // invoice parameters 'attachments' => \[$file >id] ]);invoice = client invoice create( \# invoice parameters attachments=\[file id] )invoice = invoiced invoice create( \# invoice parameters \ attachments => \[file id] ) and the file is now attached! it will be available in the client view and dashboard as a downloadable attachment retrieving attachments for an invoice you can also retrieve the existing file attachments for an invoice with a simple api query this might be useful to synchronize the attachments for an invoice with your internal systems