# Getting started

Official Pesatime API documentation

## Overview

This describes the resources that allows you to take control of you data in the **Pesatime** platform.(An insanely easy to use Online Accounting Software)

If you don't have an account, you can create one for free here [**www.pesatime.com**](http://www.pesatime.com)

## API Version

Our current version  is `v1` and hence all the requests should be made to `https://api.pesatime.com/v1/`


# Authorization

How to make valid API requests

## Request Authentication

To authenticate API requests, we use a combination of business Api secrets and a developer account user ID. Every transaction logged in the system is accompanied by the specific user which performed the operations and thats the reason as to why we have the developer User Id.

These are the required header parameters

1. `x-rest-api-key` : **\[PUT YOUR API KEY HERE]**
2. `x-rest-user` : **\[PUT YOUR DEV USER ID HERE]**

> Get your developer details here <https://app.pesatime.com/business/developer>


# Example requests

Samples on how to make requests

## Headers

1. **Content Type:** Set content type to `application/x-www-form-urlencoded`

## Requests

### 1. GET Request

```
curl -i \
    -H "x-rest-api-key: XXXXXXXX-XXX" \
    -H "x-rest-user: XXXXXXXXXXXXXX" \
    -X GET \
    https://api.pesatime.com/v1/expenses?date_from=2019-01-01
```

### 2. POST request

```
curl -i \
    -H "x-rest-api-key: XXXXXXXX-XXX" \
    -H "x-rest-user: XXXXXXXXXXXXXX" \
    -X POST -d 'name=Category name' \
    https://api.pesatime.com/v1/expense_categories
```

### 3. PUT request

```
curl -i \
    -H "x-rest-api-key: XXXXXXXX-XXX" \
    -H "x-rest-user: XXXXXXXXXXXXXX" \
    -X PUT -d 'name=Category name 2' \
    https://api.pesatime.com/v1/expense_categories/5dce9cea07f72fd690252d74
```

### 4. DELETE request

```
curl -i \
    -H "x-rest-api-key: XXXXXXXX-XXX" \
    -H "x-rest-user: XXXXXXXXXXXXXX" \
    -X DELETE \
    https://api.pesatime.com/v1/expense_categories/5dce9cea07f72fd690252d74
```


# Expense categories

Shows you how to manage expense categories

## CREATE

<mark style="color:green;">`POST`</mark> `https://api.pesatime.com/v1/expense_categories`

Create a new expense category

#### Request Body

| Name | Type   | Description                        |
| ---- | ------ | ---------------------------------- |
| name | string | The name of the category to create |

{% tabs %}
{% tab title="200 Category successfully created." %}

```javascript
{
  "status": 1,
  "message": "Saved",
  "data": {
    "_id": "5dce4b8a4d44af36f693cd2b"
  }
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Error message here"
}
```

{% endtab %}
{% endtabs %}

## UPDATE

<mark style="color:orange;">`PUT`</mark> `https://api.pesatime.com/v1/expense_categories/:categoryId`

Update an expense category

#### Request Body

| Name | Type   | Description                  |
| ---- | ------ | ---------------------------- |
| name | string | The new name of the category |

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

```
{
  "status": 1,
  "message": "Category updated successfully"
}
```

{% endtab %}

{% tab title="302 " %}

```
{
  "status": 0,
  "message": "Error description here"
}
```

{% endtab %}
{% endtabs %}

## RETRIEVE

<mark style="color:blue;">`GET`</mark> `https://api.pesatime.com/v1/expense_categories/:categoryId`

Retrieves the contents of an expense category

#### Path Parameters

| Name       | Type   | Description                                    |
| ---------- | ------ | ---------------------------------------------- |
| categoryId | string | The ID of the category to retrieve details for |

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

```
{
  "status": 1,
  "data": {
    "active": true,
    "_id": "5dcc0fc3a9e5e668a62c72e1",
    "organization": "5db5a64a6cb3e2060a7b864c",
    "user": "5cded7f553ea376e8bba6bfd",
    "name": "Salary",
    "dateCreated": "2019-11-13T14:14:27.095Z",
    "__v": 0
  }
}
```

{% endtab %}

{% tab title="302 Category not found" %}

```
{
  "status": 0,
  "message": "Category not found"
}
```

{% endtab %}
{% endtabs %}

## DELETE

<mark style="color:red;">`DELETE`</mark> `https://api.pesatime.com/v1/expense_categories/:categoryId`

Delete a category

#### Path Parameters

| Name       | Type   | Description                      |
| ---------- | ------ | -------------------------------- |
| categoryId | string | The ID of the category to delete |

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

```
{
  "status": 1,
  "message": "Category deleted successfully"
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Error description here"
}
```

{% endtab %}
{% endtabs %}


# Expenses

Manage expenses

## CREATE

<mark style="color:green;">`POST`</mark> `https://api.pesatime.com/v1/expenses`

Record a new expense

#### Request Body

| Name        | Type   | Description                                        |
| ----------- | ------ | -------------------------------------------------- |
| description | string | Add any other information here                     |
| category    | string | The category ID                                    |
| date        | string | The date of the expense in format YYYY-MM-DD HH:MM |
| amount      | number | The expense amount                                 |

{% tabs %}
{% tab title="200 Category successfully created." %}

```javascript
{
  "status": 1,
  "message": "Saved",
  "data": {
    "_id": "5dce4b8a4d44af36f693cd2b"
  }
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Error message here"
}
```

{% endtab %}
{% endtabs %}

## UPDATE

<mark style="color:orange;">`PUT`</mark> `https://api.pesatime.com/v1/expenses/:expenseId`

Update an expense

#### Path Parameters

| Name      | Type   | Description                     |
| --------- | ------ | ------------------------------- |
| expenseId | string | The ID of the expense to update |

#### Request Body

| Name        | Type   | Description                 |
| ----------- | ------ | --------------------------- |
| description | string | New description for the exp |
| category    | string | The new category ID         |
| date        | string | Date in format YYYY-MM-DD   |
| amount      | number | The new amount              |

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

```
{
  "status": 1,
  "message": "Expense updated successfully"
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Error description here"
}
```

{% endtab %}
{% endtabs %}

## RETRIEVE - All

<mark style="color:blue;">`GET`</mark> `https://api.pesatime.com/v1/expenses`

Retrieves all expenses

#### Path Parameters

| Name      | Type   | Description                                   |
| --------- | ------ | --------------------------------------------- |
| expenseID | string | The ID of the expense to retrieve details for |

#### Query Parameters

| Name        | Type   | Description                                              |
| ----------- | ------ | -------------------------------------------------------- |
| description | string | Search part of the description                           |
| category    | string | The ID of the category                                   |
| date\_to    | string | Date expense incurred *(YYYY-MM-DD)* e.g. **2019-10-14** |
| date\_from  | string | Date expense incurred *(YYYY-MM-DD)* e.g. **2019-10-13** |

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

```
{
  "status": 1,
  "data": [
    {
      "amount": 10001,
      "active": true,
      "_id": "5dce51d0bf6c524c59a75c96",
      "organization": "5db5a64a6cb3e2060a7b864c",
      "user": "5cded7f553ea376e8bba6bfd",
      "category": {
        "_id": "5cdfb75bb8f2b84e5fb55ce6",
        "name": "Office supplies"
      },
      "description": "20 copies ",
      "date": "2019-01-23T00:00:00.000Z",
      "attachments": [],
      "dateCreated": "2019-11-15T07:20:48.818Z",
      "__v": 0
    },
    
    .......
  
  ]
}
```

{% endtab %}

{% tab title="302 Expense not found" %}

```
{
  "status": 1,
  "data": []
}
```

{% endtab %}
{% endtabs %}

## RETRIEVE - single item

<mark style="color:blue;">`GET`</mark> `https://api.pesatime.com/v1/expenses/:expenseId`

Get details of one item

#### Path Parameters

| Name      | Type   | Description                          |
| --------- | ------ | ------------------------------------ |
| expenseId | string | Id of the expense to get details for |

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

```
{
  "status": 1,
  "data": {
    "amount": 10001,
    "active": true,
    "_id": "5dce51d0bf6c524c59a75c96",
    "organization": "5db5a64a6cb3e2060a7b864c",
    "user": "5cded7f553ea376e8bba6bfd",
    "category": {
      "_id": "5cdfb75bb8f2b84e5fb55ce6",
      "name": "Office supplies"
    },
    "description": "20 copies ",
    "date": "2019-01-23T00:00:00.000Z",
    "attachments": [],
    "dateCreated": "2019-11-15T07:20:48.818Z",
    "__v": 0
  }
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Expense with this id was not found"
}
```

{% endtab %}
{% endtabs %}

## DELETE

<mark style="color:red;">`DELETE`</mark> `https://api.pesatime.com/v1/expenses/:expenseId`

Delete a category

#### Path Parameters

| Name      | Type   | Description                     |
| --------- | ------ | ------------------------------- |
| expenseId | string | The ID of the expense to delete |

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

```
{
  "status": 1,
  "message": "Expense deleted successfully"
}
```

{% endtab %}

{% tab title="302 " %}

```
{
  "status": 0,
  "message": "Error description"
}
```

{% endtab %}
{% endtabs %}


# Income categories

Shows you how to manage income categories

## CREATE

<mark style="color:green;">`POST`</mark> `https://api.pesatime.com/v1/income_categories`

Create a new category

#### Request Body

| Name | Type   | Description              |
| ---- | ------ | ------------------------ |
| name | string | The name of the category |

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

```
{
  "status": 1,
  "message": "Saved",
  "data": {
    "_id": "5dce4b8a4d44af36f693cd2b"
  }
}
```

{% endtab %}

{% tab title="302 ERROR" %}

```
{
  "status": 0,
  "message": "Error description here"
}
```

{% endtab %}
{% endtabs %}

## UPDATE

<mark style="color:orange;">`PUT`</mark> `https://api.pesatime.com/v1/income_categories/:categoryId`

Update category

#### Path Parameters

| Name       | Type   | Description                      |
| ---------- | ------ | -------------------------------- |
| categoryId | string | The ID of the category to update |

#### Request Body

| Name | Type   | Description  |
| ---- | ------ | ------------ |
| name | string | The new name |

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

```
{
  "status": 1,
  "message": "Category updated successfully"
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Error description here"
}
```

{% endtab %}
{% endtabs %}

## RETRIEVE

<mark style="color:blue;">`GET`</mark> `https://api.pesatime.com/v1/income_categories/:categoryId`

Get category details

#### Path Parameters

| Name       | Type   | Description                               |
| ---------- | ------ | ----------------------------------------- |
| categoryId | string | The ID of the category to get details for |

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

```
{
  "status": 1,
  "data": {
    "active": true,
    "_id": "5dcc0fc3a9e5e668a62c72e1",
    "organization": "5db5a64a6cb3e2060a7b864c",
    "user": "5cded7f553ea376e8bba6bfd",
    "name": "Grocerries sale",
    "dateCreated": "2019-11-13T14:14:27.095Z",
    "__v": 0
  }
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Category not found"
}
```

{% endtab %}
{% endtabs %}

## DELETE

<mark style="color:red;">`DELETE`</mark> `https://api.pesatime.com/v1/expense_categories/:categoryId`

Delete category

#### Path Parameters

| Name       | Type   | Description                      |
| ---------- | ------ | -------------------------------- |
| categoryId | string | The ID of the category to delete |

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

```
{
  "status": 1,
  "message": "Category deleted successfully"
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Error description here"
}
```

{% endtab %}
{% endtabs %}


# Income

Manage income

## CREATE

<mark style="color:green;">`POST`</mark> `https://api.pesatime.com/v1/income`

Record a new sale

#### Request Body

| Name        | Type   | Description                                            |
| ----------- | ------ | ------------------------------------------------------ |
| category    | string | Category ID                                            |
| amount      | number | Amount                                                 |
| date        | string | The date this sale was made YYYY-MM-DD e.g. 2019-11-03 |
| description | string | Add any notes                                          |

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

```
{
  "status": 1,
  "message": "Saved",
  "data": {
    "_id": "5dce4b8a4d44af36f693cd2b"
  }
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Error message here"
}
```

{% endtab %}
{% endtabs %}

## UPDATE

<mark style="color:orange;">`PUT`</mark> `https://api.pesatime.com/v1/income/:incomeId`

Update an income

#### Path Parameters

| Name     | Type   | Description          |
| -------- | ------ | -------------------- |
| incomeId | string | The ID of the income |

#### Request Body

| Name        | Type   | Description               |
| ----------- | ------ | ------------------------- |
| date        | string | Date in format YYYY-MM-DD |
| description | string | The new description       |
| amount      | number | The new amount            |
| category    | number | New category ID           |

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

```
{
  "status": 1,
  "message": "Expense updated successfully"
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Error description here"
}
```

{% endtab %}
{% endtabs %}

## DELETE

<mark style="color:red;">`DELETE`</mark> `https://api.pesatime.com/v1/income/:incomeId`

Delete a sale

#### Path Parameters

| Name     | Type   | Description              |
| -------- | ------ | ------------------------ |
| incomeId | string | ID of the sale to delete |

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

```
{
  "status": 1,
  "message": "Expense deleted successfully"
}
```

{% endtab %}

{% tab title="302 Error" %}

```
{
  "status": 0,
  "message": "Error description here"
}
```

{% endtab %}
{% endtabs %}

## RETRIEVE - All

<mark style="color:blue;">`GET`</mark> `https://api.pesatime.com/v1/income`

Retrieve all sales made

#### Query Parameters

| Name        | Type   | Description                      |
| ----------- | ------ | -------------------------------- |
| category    | string | Category ID                      |
| description | string | Contains any of what is put here |
| date\_from  | string | The date this sale was made      |
| date\_from  | string | The date this sale was made      |

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

```
{
  "status": 1,
  "data": [
    {
      "amount": 10001,
      "active": true,
      "_id": "5dce51d0bf6c524c59a75c96",
      "organization": "5db5a64a6cb3e2060a7b864c",
      "user": "5cded7f553ea376e8bba6bfd",
      "category": {
        "_id": "5cdfb75bb8f2b84e5fb55ce6",
        "name": "Marketing"
      },
      "description": "New marketing deal",
      "date": "2019-01-23T00:00:00.000Z",
      "attachments": [],
      "dateCreated": "2019-11-15T07:20:48.818Z",
      "__v": 0
    },
    
    .......
  
  ]
}
```

{% endtab %}
{% endtabs %}

## RETRIEVE - single item

<mark style="color:blue;">`GET`</mark> `https://api.pesatime.com/v1/income/:incomeId`

Retrieve contents of one sale item

#### Query Parameters

| Name     | Type   | Description                |
| -------- | ------ | -------------------------- |
| incomeId | string | The ID of the item to pull |

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

```
{
  "status": 1,
  "data": {
    "amount": 10001,
    "active": true,
    "_id": "5dce51d0bf6c524c59a75c96",
    "organization": "5db5a64a6cb3e2060a7b864c",
    "user": "5cded7f553ea376e8bba6bfd",
    "category": {
      "_id": "5cdfb75bb8f2b84e5fb55ce6",
      "name": "Marketing"
    },
    "description": "Description here",
    "date": "2019-01-23T00:00:00.000Z",
    "attachments": [],
    "dateCreated": "2019-11-15T07:20:48.818Z",
    "__v": 0
  }
}
```

{% endtab %}
{% endtabs %}


# Income Reports

Income / sales specific reports

## Sum

Get sum of all sales

<mark style="color:green;">`GET`</mark> `https://api.pesatime.com/v1/reports/sum`

#### Request Body

<table><thead><tr><th width="143.75">Name</th><th width="115.421875">Type</th><th width="111.5234375">Required</th><th>Description</th></tr></thead><tbody><tr><td>date_from</td><td>Date</td><td><mark style="color:red;">yes</mark></td><td>Date from in format - YYYY-MM-DD</td></tr><tr><td>date_to</td><td>Date</td><td><mark style="color:red;">yes</mark></td><td>Date to in format - YYYY-MM-DD</td></tr><tr><td>groupBy</td><td>Object</td><td>no</td><td><p>Follows mongodb grouping standards. See below instructions for grouping.<br>properties allowed for grouping - </p><pre class="language-json"><code class="lang-json">date -> $date
-----
Example
------
{
    "date": {
        "$dateToString": {
            "format": "%2025-%01-%01",
            "date": "$date"
        }
    }
}
</code></pre></td></tr></tbody></table>


