Attachments

This section describes the API of the expense resource. It covers only listing, updating and destructing actions. If you would like to create a new attachment, please visit Uploads section.

Allowed file extentions

  • image/jpeg
  • image/jpg
  • image/gif
  • image/png
  • image/tiff
  • application/pdf
  • application/xml
  • text/xml

Example of Attachment

    {
      "id": 1,
      "description": "Hotel in China",
      "uploaded_at" : "2014-06-23T14:31:14Z",
      "content_type": "image/png",
      "file_name": "expense.png",
      "url": "https://rexpense-direct-uploads.s3.amazonaws.com/uploads/1/original/expense.png",
      "user": {
        "id": 1,
        "first_name": "John",
        "last_name": "Rexpense",
        "mention_name": "JohnRexpense",
        "emails": [
          {
            "email": "john@rexpense.com",
            "main": true
          }
        ]
      }
    }
    

List attachments

List all attachments of an expense. It will return a collection informations containing the total of record, total_pages, current_page and a set of attachments objects.

Parameters

page: integer
per_page: integer limit to 100

Definition

GET https://app.rexpense.com/api/v1/expenses/:expense_id/attachments

Example Request

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

Response Example

    {
      "count": 1,
      "current_page": 1,
      "total_pages": 1,
      "attachments": [
        {
          "id": 1,
          "description": "Hotel in China",
          "uploaded_at" : "2014-06-23T14:31:14Z",
          ...
        }
      ]
    }
    

Show an attachment

This request shows the attachment complete information. It will return an attachment object representation.

Parameters

id: integer required

Definition

GET https://app.rexpense.com/api/v1/expenses/:expense_id/attachments/:id

Example Request

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

Response Example Success

HTTP 200 OK
    {
      "id": 1,
      "description": "Hotel in China",
      "uploaded_at" : "2014-06-23T14:31:14Z",
      ...
    }
    

Response Example Failure

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

Update an attachment

This request updates attachments informations. It will return an attachment object representation. There are two ways to update a attachment: 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 attachment.

Parameters

file: string
description: string

The file parameter must be an URL of the attachment. This URL may be achieve following the steps in Uploads section.

Definition

PUT/PATCH https://app.rexpense.com/api/v1/expenses/:expense_id/attachments/:id

Example Request

$ curl -u $YOUR_API_TOKEN:X -X PATCH https://app.rexpense.com/api/v1/expenses/1/attachments/1 \
      -H 'Accept: application/json' \
      -H 'Content-type: application/json' \
      -d '{"description":"Travel to Paris"}'

Response Example Success

HTTP 200 OK
    {
      "id": 1,
      "description": "Travel to Paris",
      "uploaded_at" : "2014-06-23T14:31:14Z",
      ...
    }
    

Response Example Failure

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

Destroy an attachment

This request destroy an attachment. It will return an empty body.

Parameters

id: integer required

Definition

DELETE https://app.rexpense.com/api/v1/expenses/:expense_id/attachments/:id

Example Request

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

Response Example Success

HTTP 204 No Content