How can we help?

How to upload expense files using the API?

Noga Tubi
Noga Tubi
  • Updated
Upload expense files using Torii's APIs

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

Uploading an expense file to Torii using the API consists of 2 steps:

  1. Uploading the file (requires 3 API requests)

  2. Parsing the file to extract expenses (requires a single API request)

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

 

CONTENT_TYPE

The content-type of your file

For example: text/csv

FILE_TYPE

Torii's file type

For expenses, type is: expenseReport

FILE_PATH

Internally used

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

S3_URL

The pre-signed URL

This parameter is returned from https://api.toriihq.com/beta/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/beta/parsings/(automatic|manual)

 

Instructions

STEP 1: Uploading an expense file

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

  • A) Get the required parameters for uploading your file:

curl -H "Authorization: Bearer API_KEY" "https://api.toriihq.com/beta/files/url?name={FILE_NAME}&type={CONTENT_TYPE}"

 

Example response:

{ 
"uploadFileParameters": {
"url": "S3_URL",
"filePath": "1612686123657/test_file.xlsx"
}
}
  • B) Use the S3_URL provided in the previous step to upload your file:

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

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

 

 

STEP 2: Parsing an expense file

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/beta/parsings/automatic

 

Notes:

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

  • If automatic parsing did not succeed, use "manual column matching" via this endpoint: https://api.toriihq.com/beta/parsings/manual. (Check the Parse manually API in our docs for more information)

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request