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:
-
Uploading the file (requires 3 API requests)
-
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: |
FILE_TYPE |
Torii's file type |
For expenses, type is: |
FILE_PATH |
Internally used |
This parameter is returned from |
S3_URL |
The pre-signed URL |
This parameter is returned from |
FILE_ID |
Unique file identifier |
This parameter is returned from |
PARSING_ID |
Unique parsing identifier |
This parameter is returned from |
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/v1.0
/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/v1.0
/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/v1.0
/parsings/automatic
Notes:
-
Parsing a file may take some time, so after sending a parse request, make sure to poll
https://api.toriihq.com/v1.0/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/v1.0/parsings/manual
. (Check theParse manually
API in our docs for more information)