Who is this article for?

You are a developer, with knowledge of REST API usage, tasked with uploading an expense report file to Torii.

Introduction

Files uploaded to Torii are stored in AWS's S3 service.

To optimize the security and performance of this process, a private, pre-signed URL is generated for the user whenever they request to upload a file. They then use this URL to upload the file directly to S3. Once the file has been uploaded successfully, the user must inform Torii.

Prerequisites

To use Torii's APIs, you must have a valid API key.

Learn how to use the API here.

Terms

Term

Description

Comments

API_KEY

Torii's API key

FILE_NAME

The full name of your file

FILE_TYPE

Torii's file type

For expenses, type is: expenseReport

FILE_PATH

Internally used

This parameter is returned from https://api.toriihq.com/files/url

S3_URL

The pre-signed URL

This parameter is returned from https://api.toriihq.com/files/url

FILE_ID

Unique file identifier

This parameter is returned from https://api.toriihq.com/beta/files

PARSING_ID

Unique parsing identifier

This parameter is returned from https://api.toriihq.com/parsings/(automatic|manual)

Usage

Uploading an expense file

In order to upload an expense file to Torii using our APIs, follow these steps:

  • Get the required parameters for uploading your file:

curl -H "Authorization: Bearer API_KEY" https://api.toriihq.com/files/url?name={FILE_NAME}&type={FILE_TYPE}
  • Use the pre-signed URL to upload your file directly to S3:

curl -H "Content-Type: {FILE_TYPE}" --data-binary '@PATH/TO/YOUR/FILE' -X PUT {S3_URL}
  • Inform Torii that the file has been successfully uploaded:

curl -d '{"path":"{FILE_PATH}","type":'{FILE_TYPE}'}' -H "Authorization: Bearer API_KEY" -H "Content-Type: application/json" https://api.toriihq.com/beta/files

Parsing an expense file

Notes:

  • Parsing a file may take some time, so after sending a parse request, make sure to poll https://api.toriihq.com/parsings/{PARSING_ID} to verify that the request was successful

  • Parsing can also be done with manual column matching via this endpoint: https://api.toriihq.com/parsings/manual. (Check the Parse manually API in our docs for more information)

Use the following code snippet to parse an expense file with automatic column matching:

curl -X PUT -d '{"idFile":"{FILE_ID}"}' -H "Authorization: Bearer API_KEY" https://api.toriihq.com/parsings/automatic
Did this answer your question?