# Transactions

## List all transactions

<mark style="color:blue;">`GET`</mark> `https://app.gem-books.com/api/transactions`

This endpoint allows you to get the list of your transactions. \
The transactions are returned sorted by creation date, with the most recent transaction appearing first.

#### Headers

| Name             | Type   | Description                   |
| ---------------- | ------ | ----------------------------- |
| Authentification | string | Bearer token.                 |
| Accept           | string | Should be `application/json`. |

{% tabs %}
{% tab title="200 " %}

```
{
    "data": [
        {
            "id": 13033,
            "number": "13017",
            "reference": "test",
            "date": "2020-08-17",
            "user": "AAA",
            "creation_date": "2020-08-18",
            "creation_time": "11:18:31",
            "description": "This is a test!",
            "name": "test",
            "period": "Current",
            "code": null,
            "details": [
                {
                    "account": "1200",
                    "reference": "test",
                    "amount": "10.00",
                    "currency": "CAD",
                    "credit": "C"
                },
                {
                    "account": "4020",
                    "reference": "test",
                    "amount": "10.00",
                    "currency": "CAD",
                    "credit": "D"
                }
            ]
        },
        {
            "id": 13032,
            "number": "13016",
            "reference": "test",
            "date": "2020-08-17",
            "user": "AAA",
            "creation_date": "2020-08-18",
            "creation_time": "11:17:54",
            "description": "This is a test!",
            "name": "Test",
            "period": "Current",
            "code": null,
            "details": [
                {
                    "account": "1200",
                    "reference": "test",
                    "amount": "10.00",
                    "currency": "CAD",
                    "credit": "C"
                },
                {
                    "account": "4020",
                    "reference": "test",
                    "amount": "10.00",
                    "currency": "CAD",
                    "credit": "D"
                }
            ]
        }
    ],
    "meta": {
        "current_page": 1,
        "last_page": 521,
        "per_page": 25,
        "total": 13021
    },
    "success": true
}
```

{% endtab %}
{% endtabs %}

## Retrieve a transaction

<mark style="color:blue;">`GET`</mark> `https://app.gem-books.com/api/transactions/:id`

This endpoint allows you to access a specific transaction by its ID.

#### Path Parameters

| Name | Type   | Description        |
| ---- | ------ | ------------------ |
| id   | string | ID of transaction. |

#### Headers

| Name             | Type   | Description                   |
| ---------------- | ------ | ----------------------------- |
| Authentification | string | Bearer token.                 |
| Accept           | string | Should be `application/json`. |

{% tabs %}
{% tab title="200 " %}

```
{
    "data": {
        "id": 13033,
        "number": "13017",
        "reference": "test",
        "date": "2020-08-17",
        "user": "AAA",
        "creation_date": "2020-08-18",
        "creation_time": "11:18:31",
        "description": "This is a test!",
        "name": "test",
        "period": "99999",
        "code": null,
        "details": [
            {
                "account": "1200",
                "reference": "test",
                "amount": "10.00",
                "currency": "CAD",
                "credit": "C"
            },
            {
                "account": "4020",
                "reference": "test",
                "amount": "10.00",
                "currency": "CAD",
                "credit": "D"
            }
        ]
    },
    "success": true
}
```

{% endtab %}
{% endtabs %}

## Create a transaction

<mark style="color:green;">`POST`</mark> `https://app.gem-books.com/api/transactions`

This endpoint allows you to create a new transaction. \
The new transaction will be returned.

#### Headers

| Name             | Type   | Description                   |
| ---------------- | ------ | ----------------------------- |
| Authentification | string | Bearer token.                 |
| Accept           | string | Should be `application/json`. |
| Content-Type     | string | Should be `application/json`. |

#### Request Body

| Name        | Type   | Description                                                                                                                                                        |
| ----------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| code        | string | Provider or client code, this will be applied to all details using the provider or client's account. Only one provider or one client can be sent in a single call. |
| reference   | string | Transaction reference.                                                                                                                                             |
| date        | string | Transaction date.                                                                                                                                                  |
| details     | array  | All transaction legs (account,amount,currency,credit,reference,projet\_id).                                                                                        |
| description | string | Transaction description.                                                                                                                                           |

{% tabs %}
{% tab title="200 " %}

```
{
    "data": {
        "id": 13033,
        "number": "13017",
        "reference": "test",
        "date": "2020-08-17",
        "user": "AAA",
        "creation_date": "2020-08-18",
        "creation_time": "11:18:31",
        "description": "This is a test!",
        "name": "test",
        "period": "99999",
        "code": null,
        "details": [
            {
                "account": "1200",
                "reference": "test",
                "amount": "10.00",
                "currency": "CAD",
                "credit": "C"
            },
            {
                "account": "4020",
                "reference": "test",
                "amount": "10.00",
                "currency": "CAD",
                "credit": "D"
            }
        ]
    },
    "success": true
}
```

{% endtab %}
{% endtabs %}

#### Body example

```
{
    "reference": "test",
    "date": "2020-08-17",
    "description": "This is a test!",
    "code": "TEST",
    "labels": "1,2,3"
    "details": [
        {
            "account" : "1200",
            "reference" : "test",
            "amount" : "10.00",
            "credit" : "C",
            "currency" : "CAD",
            "projet_id" : "0"
        },
        {
            "account" : "4020",
            "reference" : "test",
            "amount" : "10.00",
            "credit" : "D",
            "currency" : "CAD",
            "projet_id" : "0"
        }
    ]
}
```
