Pre-Expenses

This section describes the API of the Pre-Expense object. A Pre-Expense is an object that demands some intervention (approval or not) of the user to be converted into an Expense object. Usually, a Pre-Expense is a result of an integration (i.e. integration with Uber)

Parameters

id: integer
description: string
amount: float
* status: string
occurred_at: string
receiver: JSON object
tags: array
currency: string
based on currencies code
extra_information: JSON object
_links: array of object
array of links of the pre-expense

* Pre-expense status is not equivalent to Expense status. It only tells if the Pre-Expense is completed to be converted to an Expense (current available Pre-Expense statuses: completed, in_progress)

Example Pre-Expense

    {
      "id": 1,
      "description": "Expense example 1",
      "amount": 120.00,
      "status": "completed",
      "occurred_at": "2014-06-01T14:17:56Z",
      "ignored_at": null,
      "converted_at": null,
      "receiver": {
        "id": 1,
        "name": "John",
        "type": "User",
        "avatar": [
          {
            "style": "original",
            "url": "https://rexpense-uploads.s3.amazonaws.com/user_avatar/1/original/avatar.png",
            "width": 716,
            "height": 655,
            "expiration": "2014-06-27T20:31:43Z"
          },
          {
            "style": "medium",
            "url": "https://rexpense-uploads.s3.amazonaws.com/user_avatar/1/medium/avatar.png",
            "width": 300,
            "height": 300,
            "expiration": "2014-06-27T20:31:43Z"
          },
          {
            "style": "thumb",
            "url": "https://rexpense-uploads.s3.amazonaws.com/user_avatar/1/thumb/avatar.png",
            "width": 100,
            "height": 100,
            "expiration": "2014-06-27T20:31:43Z"
          }
          {
            "style": "tiny",
            "url": "https://rexpense-uploads.s3.amazonaws.com/user_avatar/1/tiny/avatar.png",
            "width": 48,
            "height": 48,
            "expiration": "2014-06-27T20:31:43Z"
          }
        ]
      },
      "tags": "lunch, conference, 2014, new clients",
      "currency": "BRL",
      "created_at": "2014-06-03T14:17:56Z",
      "updated_at": "2014-06-03T14:17:56Z",
      "deleted_at": null,
      "_links": [
        {
          "rel": "self",
          "method": "GET",
          "href": "https://app.rexpense.com/api/v1/pre_expenses/1"
        },
        {
          "rel": "ignore",
          "method": "PUT",
          "href": "https://app.rexpense.com/api/v1/pre_expenses/1/ignore"
        },
        {
          "rel": "restore",
          "method": "PATCH",
          "href": "https://app.rexpense.com/api/v1/pre_expenses/1/restore"
        },
        {
          "rel": "destroy",
          "method": "DELETE",
          "href": "https://app.rexpense.com/api/v1/pre_expenses/1"
        }
      ]
    }
    

List all Pre-Expenses

Retrieve all pre-expenses that the authenticated user has. 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.

Parameters

page: integer
per_page: integer limit to 100
status: string ignored or waiting_approval

When requesting without specifying which is the status, the default is waiting approval

Definition

GET https://app.rexpense.com/api/v1/pre_expenses

Example Request

$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/pre_expenses \
      -H 'Accept: application/json' \
      -H 'Content-type: application/json'

Response Example

    {
      "count": 1,
      "current_page": 1,
      "total_pages": 1,
      "pre_expenses": [{ "id": 1, ... }]
    }
    

Show pre-expense

Returns the detailed information of a pre-expense.

Definition

GET https://app.rexpense.com/api/v1/pre_expenses/:id

Example Request

$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/pre_expenses/1 \
       -H 'Accept: application/json' \
       -H 'Content-type: application/json'

Response Example

HTTP 200 OK
    {
      "id": 1,
      ...
    }
    

Ignore a Pre-Expense

When ignoring a Pre-Expense, it won't appear in the default list of Pre-Expenses (Pre-Expenses waiting approval of the user).

Definition

PUT https://app.rexpense.com/api/v1/pre_expenses/:id/ignore

Example Request

$ curl -u $YOUR_API_TOKEN:X -X PUT https://app.rexpense.com/api/v1/pre_expenses/1/ignore \
       -H 'Accept: application/json' \
       -H 'Content-type: application/json'

Response Example Success

HTTP 200 OK
    {
      "id": 1,
      ...
    }
    

Restore a Pre-Expense

When restoring a Pre-Expense, it will appear in the default list of Pre-Expenses (Pre-Expenses waiting approval of the user).

Definition

PUT https://app.rexpense.com/api/v1/pre_expenses/:id/restore

Example Request

$ curl -u $YOUR_API_TOKEN:X -X PUT https://app.rexpense.com/api/v1/pre_expenses/1/restore \
       -H 'Accept: application/json' \
       -H 'Content-type: application/json'

Response Example Success

HTTP 200 OK
    {
      "id": 1,
      ...
    }
    

Convert a Pre-Expense

When a Pre-Expense is converted, it creates a new Expense. To convert a Pre-Expense, you have to provide some parameters so the Expense can be created.

After created, the Expense is in its initial status Awaiting analysis and it follows its natural process.

When request is succeed, the response will contain the created Expense information with the pre_expense_id.

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

Definition

POST https://app.rexpense.com/api/v1/pre_expenses/:id/convert

Example Request

$ curl -u $YOUR_API_TOKEN:X -X POST https://app.rexpense.com/api/v1/pre_expenses/1/convert \
       -H 'Accept: application/json' \
       -H 'Content-type: application/json' \
       -d '{"description": "Some description", "amount": 125.99, "payer": {"id": 1, "type": "Organization"}, "tags": [], "liquidate_through_advancement": false}'

Response Example Success

HTTP 200 OK
    {
      "id": 2,
      "pre_expense_id": 1,
      ...
    }
    

Destroy a Pre-Expense

Definition

DELETE https://app.rexpense.com/api/v1/pre_expenses/:id

Example Request

$ curl -u $YOUR_API_TOKEN:X -X DELETE https://app.rexpense.com/api/v1/pre_expenses/:id \
        -H 'Accept: application/json' \
        -H 'Content-type: application/json'
      

Response Example

HTTP 204 NO CONTENT