Corporative cards

This section describes the API of the corporative card resource.

Parameters

id: integer
name: string
flag: JSON object
number: string
expiration_date: string
expiration_month: integer
expiration_year: integer
active: boolean
user: JSON object
organization: JSON object
_links: array of object
array of links of the corporative card

Example of Corporative card

    {
      "id": 1,
      "name": "Credit card",
      "number": "************1234",
      "flag": {
        name: "mastercard",
        image_url: 'https://...',
      },
      "expiration_date": "05/19",
      "expiration_month": 5,
      "expiration_year": 2019
      "active": true,
      "organization": {
        "id": 1,
        "name": "Company Inc.",
        "type": "Organization",
        "logo": [
          {
            "style": "original",
            "url": "https://rexpense-uploads.s3.amazonaws.com/organization_logo/1/original/logo.png",
            "expiration": "2014-06-27T20:31:43Z"
          },
          {
            "style": "medium",
            "url": "https://rexpense-uploads.s3.amazonaws.com/organization_logo/1/medium/logo.png",
            "expiration": "2014-06-27T20:31:43Z"
          },
          {
            "style": "thumb",
            "url": "https://rexpense-uploads.s3.amazonaws.com/organization_logo/1/thumb/logo.png",
            "expiration": "2014-06-27T20:31:43Z"
          }
          {
            "style": "tiny",
            "url": "https://rexpense-uploads.s3.amazonaws.com/organization_logo/1/tiny/logo.png",
            "expiration": "2014-06-27T20:31:43Z"
          }
        ]
      },
      "user": {
        "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"
          }
        ]
      },
      "created_at": "2018-06-04T14:17:56Z",
      "updated_at": "2018-06-04T14:17:56Z",
      "_links": [
        {
          "rel": "self",
          "method": "GET",
          "href": "https://app.rexpense.com/api/v1/corporative_cards/1"
        },
        {
          "rel": "update",
          "method": "PUT",
          "href": "https://app.rexpense.com/api/v1/corporative_cards/1"
        },
        {
          "rel": "partial_update",
          "method": "PATCH",
          "href": "https://app.rexpense.com/api/v1/corporative_cards/1"
        },
        {
          "rel": "destroy",
          "method": "DELETE",
          "href": "https://app.rexpense.com/api/v1/corporative_cards/1"
        }
      ]
    }
    

List all corporative cards of the user

Retrieve all corporative cards that the authenticated user have. 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 corporative cards can be found in the Corporative card section.

Parameters

page: integer
per_page: integer limit to 100

Definition

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

Example Request

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

Response Example

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

Filtering corporative cards

You can filter the list of retrieved corporative cards.

Parameters

All parameters must be nested a q parameter.

id_in: array of integer
name_cont: string
flag_cont: string
organization_id_in: array of integer
active_eq: boolean
created_at_lteq: string
updated_at_gteq: string

Definition

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

Request example

$ curl -u $YOUR_API_TOKEN:X -X GET https://app.rexpense.com/api/v1/corporative_cards \
      -H 'Accept: application/json' \
      -H 'Content-type: application/json' \
      -d '{"q": {"id": [1]}}'

Response Example

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

Show a corporative card

This request shows the corporative card complete information.

Parameters

id: integer required

Definition

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

Example Request

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

Response Example Success

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

Response Example Failure

HTTP 404 Record Not Found
    {
      "errors": {
        "message": "Record Not Found"
      }
    }
    

Create a corporative card

This request creates a new corporative card.

Important:

  • The authenticated user must belong to an organization to create a new corporative card.
  • A corporative card must be attached to an organization.

Parameters

name: string
number: string
expiration_date: string MM/YY format
organization_id: integer
user_id: integer
active: boolean

Definition

POST https://app.rexpense.com/api/v1/corporative_cards

Example Request

$ curl -u $YOUR_API_TOKEN:X -X POST https://app.rexpense.com/api/v1/corporative_cards \
        -H 'Accept: application/json' \
        -H 'Content-type: application/json' \
        -d '{"name": "Credit card", "number": "1234567890123456", "organization_id": 1, ... }'

Response Example Success

HTTP 201 CREATED
    {
      "id": 1,
      ...
    }
    

Response Example Failure

HTTP 422 Unprocessable Entity
    {
      "errors": {
        "name": ["can't be blank"]
      }
    }
    

Update a corporative card

There are two ways to update a corporative card: 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 corporative card. This behaviour is the same for all resources in the Rexpense API.

Parameters

name: string required
expiration_date: string MM/YY format
active: boolean
organization_id: integer required

Definition

PUT/PATCH https://app.rexpense.com/api/v1/corporative_cards/:id

Example Request

$ curl -u $YOUR_API_TOKEN:X -X PATCH https://app.rexpense.com/api/v1/corporative_cards/:id \
        -H 'Accept: application/json' \
        -H 'Content-type: application/json' \
        -d '{"name": "John John"}'

Response Example Success

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

Response Example Failure

HTTP 422 Unprocessable Entity
    {
      "errors": {
        "name": ["can't be blank"]
      }
    }
    

Destroy a corporative card

To destroy a corporative card it has to have no expense attached to it.

Definition

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

Example Request

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

Response Example

HTTP 204 NO CONTENT

Example Response Failure when corporative card has expenses attached to it

HTTP 422 Unprocessable entity
    {
      "errors": {
        "message": "There are expenses attached to the corporative card."
      }
    }