Xero Files API – Document library, folders, and accounting object associations.
Base URL: https://api.xero.com/files.xro/1.0/
Scopes: files or files.read
Examples
# Upload a file to the inbox
{:ok, file} = Xero.Files.upload(token, tenant_id, "invoice.pdf", pdf_bytes, "application/pdf")
# Associate with an accounting object
:ok = Xero.Files.associate(token, tenant_id, file["FileId"], invoice_id, "Invoice")
# Download the file content
{:ok, binary} = Xero.Files.download(token, tenant_id, file["FileId"])
# Move to a folder
{:ok, _} = Xero.Files.move_to_folder(token, tenant_id, file["FileId"], folder_id)
Summary
Functions
Associates a file with a Xero accounting object.
Lists all file associations for an accounting object.
Creates a new folder.
Deletes a file from the library.
Deletes a folder (must be empty).
Removes a file association from an accounting object.
Downloads the raw binary content of a file.
Lists files in a specific folder.
Retrieves a specific folder by ID.
Lists all folders. Options: :sort
Retrieves metadata for a single file by ID.
Returns the inbox folder metadata.
Lists files in the inbox.
Lists files. Options: :page_size, :page, :sort, :sort_direction
Sort values: "CreatedDateUtc" | "UpdatedDateUtc" | "Name"
Lists all associations across all files for an object group.
Moves a file to a different folder.
Renames a file.
Renames a folder.
Uploads a file to the Xero file library (inbox by default).
Uploads a file directly into a specific folder.
Functions
@spec associate(Xero.Auth.Token.t(), String.t(), String.t(), String.t(), String.t()) :: :ok | {:error, Xero.Error.t()}
Associates a file with a Xero accounting object.
Object Types
"Account" | "BankTransaction" | "Contact" | "CreditNote" |
"Invoice" | "ManualJournal" | "Receipt" | "RepeatingInvoice"
@spec associations(Xero.Auth.Token.t(), String.t(), String.t()) :: {:ok, term()} | {:error, Xero.Error.t()}
Lists all file associations for an accounting object.
@spec create_folder(Xero.Auth.Token.t(), String.t(), String.t()) :: {:ok, map()} | {:error, Xero.Error.t()}
Creates a new folder.
@spec delete(Xero.Auth.Token.t(), String.t(), String.t()) :: :ok | {:error, Xero.Error.t()}
Deletes a file from the library.
@spec delete_folder(Xero.Auth.Token.t(), String.t(), String.t()) :: :ok | {:error, Xero.Error.t()}
Deletes a folder (must be empty).
@spec disassociate(Xero.Auth.Token.t(), String.t(), String.t(), String.t()) :: :ok | {:error, Xero.Error.t()}
Removes a file association from an accounting object.
@spec download(Xero.Auth.Token.t(), String.t(), String.t()) :: {:ok, binary()} | {:error, Xero.Error.t()}
Downloads the raw binary content of a file.
@spec files_in_folder(Xero.Auth.Token.t(), String.t(), String.t(), keyword()) :: {:ok, term()} | {:error, Xero.Error.t()}
Lists files in a specific folder.
@spec folder(Xero.Auth.Token.t(), String.t(), String.t()) :: {:ok, map()} | {:error, Xero.Error.t()}
Retrieves a specific folder by ID.
@spec folders(Xero.Auth.Token.t(), String.t(), keyword()) :: {:ok, term()} | {:error, Xero.Error.t()}
Lists all folders. Options: :sort
@spec get(Xero.Auth.Token.t(), String.t(), String.t()) :: {:ok, map()} | {:error, Xero.Error.t()}
Retrieves metadata for a single file by ID.
@spec inbox(Xero.Auth.Token.t(), String.t()) :: {:ok, map()} | {:error, Xero.Error.t()}
Returns the inbox folder metadata.
@spec inbox_files(Xero.Auth.Token.t(), String.t(), keyword()) :: {:ok, term()} | {:error, Xero.Error.t()}
Lists files in the inbox.
@spec list(Xero.Auth.Token.t(), String.t(), keyword()) :: {:ok, term()} | {:error, Xero.Error.t()}
Lists files. Options: :page_size, :page, :sort, :sort_direction
Sort values: "CreatedDateUtc" | "UpdatedDateUtc" | "Name"
@spec list_associations_for_object( Xero.Auth.Token.t(), String.t(), String.t(), String.t() ) :: {:ok, term()} | {:error, Xero.Error.t()}
Lists all associations across all files for an object group.
@spec move_to_folder(Xero.Auth.Token.t(), String.t(), String.t(), String.t()) :: {:ok, map()} | {:error, Xero.Error.t()}
Moves a file to a different folder.
@spec rename(Xero.Auth.Token.t(), String.t(), String.t(), String.t()) :: {:ok, map()} | {:error, Xero.Error.t()}
Renames a file.
@spec rename_folder(Xero.Auth.Token.t(), String.t(), String.t(), String.t()) :: {:ok, map()} | {:error, Xero.Error.t()}
Renames a folder.
@spec upload(Xero.Auth.Token.t(), String.t(), String.t(), binary(), String.t()) :: {:ok, map()} | {:error, Xero.Error.t()}
Uploads a file to the Xero file library (inbox by default).
Parameters
filename— File name including extension (e.g."invoice.pdf")content— Binary file contentcontent_type— MIME type (e.g."application/pdf","image/jpeg")
@spec upload_to_folder( Xero.Auth.Token.t(), String.t(), String.t(), String.t(), binary(), String.t() ) :: {:ok, map()} | {:error, Xero.Error.t()}
Uploads a file directly into a specific folder.