Expenses
This section describes the API of the expense resource.
Parameters
id: | integer |
kind: | string |
description: | string |
distance: | float |
distance_kind: | string |
destination: | string |
destination_latitude: | float |
destination_longitude: | float |
origin: | string |
origin_latitude: | float |
origin_longitude: | float |
travel_time: |
string String format "HH:MM" |
amount: | float |
approved_amount: | float |
status: | string |
occurred_at: | string |
payer: | JSON object |
receiver: | JSON object |
attachments: |
array of objects array of an attachment representation |
tags: | array |
currency: | string based on currencies code |
approved_amount_currency: | string based on currencies code |
latitude: | float |
longitude: | float |
location: | string |
attachments_count: | integer |
comments_count: | integer |
activities_count: | integer |
liquidation_through: | string (advancement, reimbursement or corporative_card) |
_links: |
array of object array of links of the expense |
The following parameters will only available when the expense kind is distance.
distance: | float |
distance_kind: | string |
destination: | string |
destination_latitude: | float |
destination_longitude: | float |
origin: | string |
origin_latitude: | float |
origin_longitude: | float |
travel_time: |
string String format "HH:MM" |
Example of Expense
List all expenses
Retrieve all expenses that the authenticated user can view or manage. It will return a JSON
containing the name of the resource
with an array of the objects requested and informations like the total of objects, current page and total pages. The fields of the expenses can be
found in the Expense section.
Parameters
page: | integer |
per_page: | integer limit to 100 |
Definition
GET https://app.rexpense.com/api/v1/expenses
Example Request
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/expenses \ -H 'Accept: application/json' \ -H 'Content-type: application/json'
Response Example
Filtering a list of expenses
You can filter the list of retrieved expenses.
Parameters
All parameters must be nested a 'q' parameter.
status_in: | string |
amount_gteq: | float |
amount_lteq: | float |
receiver_id_eq: | integer |
payer_id_eq: | integer |
created_at_gteq: | string |
created_at_lteq: | string |
updated_at_gteq: | string |
updated_at_lteq: | string |
search_tags: | string |
has_tag: |
array of string accepted values: '1', '0', '' |
liquidation_through_in: |
array of strings accepted values: advancement, reimbusement, corporative_card |
corporative_card_id_in: |
array of integers |
Definition
GET https://app.rexpense.com/api/v1/expensess
Request example
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/expenses \
-H 'Accept: application/json' \
-H 'Content-type: application/json' \
-d '{"q": {"status_in":"awaiting_analysis"}}'
Response Example
Request example
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/expenses \
-H 'Accept: application/json' \
-H 'Content-type: application/json' \
-d '{"q": {"amount_gteq":3000.00, "amount_lteq": 4000.00}}'
Response Example
Request example
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/expenses \
-H 'Accept: application/json' \
-H 'Content-type: application/json' \
-d '{"q": {"receiver_id_eq": 1}}'
Response Example
Request example
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/expenses \
-H 'Accept: application/json' \
-H 'Content-type: application/json' \
-d '{"q": {"payer_id_eq": 1}}'
Response Example
Request example
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/expenses \
-H 'Accept: application/json' \
-H 'Content-type: application/json' \
-d '{"q": {"created_at_gteq": "12-24-2013", "created_at_lteq": "12-25-2013"}}'
Response Example
Request example
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/expenses \
-H 'Accept: application/json' \
-H 'Content-type: application/json' \
-d '{"q": {"updated_at_gteq": "12-24-2013", "updated_at_lteq": "12-25-2013"}}'
Response Example
Show an expense
This request shows the expense complete information.
If the Expense is originated from a Pre-Expense, it will contain the field pre_expense_id
. To learn more about PreExpense visit its section.
Parameters
id: | integer required |
Definition
GET https://app.rexpense.com/api/v1/expenses/:id
Example Request
$ curl -u $YOUR_API_TOKEN:X -X POST https://app.rexpense.com/api/v1/expenses/1 \ -H 'Accept: application/json' \ -H 'Content-type: application/json'
Response Example Success
HTTP 200 OK
Response Example Failure
HTTP 404 Record Not Found
Create an expense
This request creates a new expense.
Important:
- The authenticated user must belong to an organization to create a new expense.
- It's not possible to set
attachments_count
,comments_count
andactivities_count
fields.
Parameters
description: | string |
payer: |
payer object attributes required
id: integer
type: string |
amount: | float required |
occurred_at: | string iso8601 format required |
tags: | string |
latitude: | float |
longitude: | float |
location: | string |
liquidation_through: |
string required accepted values: advancement, reimbursement or corporative_card |
corporative_card_id: |
integer optional required only when liquidation_through is corporative_card |
To create an expense with distance kind, you have to send the kind
param with "distance" value. In travel values is required distance
and distance_kind
where can be "km" or "mi". The travel_time
field receive a string in format "HH:MM" and show minutes value, example: "01:01" returns 61 minutes.
Distance expenses d'not need amount
, but have send distance informations:
kind: | string required |
distance: | string required |
distance_kind: | string required |
destination: | string |
destination_latitude: | float |
destination_longitude: | float |
origin: | string |
origin_latitude: | float |
origin_longitude: | float |
travel_time: | string |
To create an expense with attachments, you have to send the attachments_attributes
parameters. This parameters is an array containing one or multiple JSON objects with the following information:
file: | string required |
description: | string |
The file
parameter must be an URL of the attachment. This URL may be achieve following
the steps in Uploads section.
Expired organization
If the organization is expired, it will return an 402 error.
Definition
POST https://app.rexpense.com/api/v1/expenses
Example Request
$ curl -u $YOUR_API_TOKEN:X -X POST https://app.rexpense.com/api/v1/expenses \ -H 'Accept: application/json' \ -H 'Content-type: application/json' \ -d '{"amount": 1000.00, "occurred_at": "2013-12-24", "payer": {"id": 1, "type": "Organization"}}'
Response Example Success
HTTP 201 CREATED
Response Example Failure
HTTP 422 Unprocessable Entity
Example Response Failure when organization is expired
HTTP 402 Payment Required
Update an expense
There are two ways to update an expense: partially or fully. If you'd like to change just one or
a few attributes, you have to use the HTTP method PATCH
. If you use the HTTP method PUT
, you'll have to
pass all attributes of the expense. This behaviour is the same for all resources in the Rexpense API.
Parameters
description: | string |
amount: | float required |
approved_amount: | float |
occurred_at: | string required |
tags: | string |
latitude: | float |
longitude: | float |
location: | string |
liquidation_through: |
string accepted values: advancement, reimbursement or corporative_card |
corporative_card_id: | string optional (only when liquidation_through is corporative_card) |
To create an expense with distance kind, you have to send the kind
param with "distance" value.
Distance expenses d'not need amount
, but have send distance informations:
distance: | string required |
distance_kind: | string required |
destination: | string required |
destination_latitude: | float |
destination_longitude: | float |
origin: | string required |
origin_latitude: | float |
origin_longitude: | float |
travel_time: | string |
To update the expense's attachments, you have to send the attachments_attributes
parameters. This parameter is an array containing JSON objects with the following information:
id: | integer |
description: | string |
file: | string required |
_destroy: | boolean |
The file
parameter must be an URL of the attachment. This URL may be achieve following
the steps in Uploads section.
To remove an attachment, you have to pass the _destroy
parameter with value true
and the id
with the id of the attachment to be removed.
Status 'Pending'
When updating a Pending
expense, it'll change its status to Awaiting analysis
, so an Administrator/Manager/Analyst can check the new informations on the expense.
Expired organization
If the organization is expired, it will return an 402 error.
Definition
PUT/PATCH https://app.rexpense.com/api/v1/expenses/:id
Example Request
$ curl -u $YOUR_API_TOKEN:X -X PATCH https://app.rexpense.com/api/v1/expenses/:id \ -H 'Accept: application/json' \ -H 'Content-type: application/json' \ -d '{"approved_amount": 1200.00, "occurred_at": "2013-12-28"}'
Response Example Success
HTTP 200 OK
Response Example Failure
HTTP 422 Unprocessable Entity
Example Response Failure when organization is expired
HTTP 402 Payment Required
Destroy an expense
To destroy an expense you have to own the expense (be the receiver) and it's status must be Awaiting analysis. Also an Organization's Administrator or Manager can destroy any expense that belongs to the organization.
Expired organization
If the organization is expired, it will return an 402 error.
Definition
DELETE https://app.rexpense.com/api/v1/expenses/:id
Example Request
$ curl -u $YOUR_API_TOKEN:X -X DELETE https://app.rexpense.com/api/v1/expenses/:id \ -H 'Accept: application/json' \ -H 'Content-type: application/json'
Response Example
HTTP 204 NO CONTENT
Example Response Failure when organization is expired
HTTP 402 Payment Required
Expense's activities
Activities are simple logs from an Expense's changes or comments activities.
If the activity is an Expense change, the response will hide the source
element from the response.
If the activity is a Comment and the content
have emojis, they will be rendered as text code by default (for example, :smile:
). However, if you'd like to get the unicode of the emojis instead, you should supply a emoji_in_unicode
boolean param.
Parameter
emoji_in_unicode: | boolean |
Definition
GET https://app.rexpense.com/api/v1/expenses/:expense_id/activities
Example request
$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/expenses/1/activities \ -H 'Accept: application/json' \ -H 'Content-type: application/json'
Response Example Success
HTTP 200 OK