# Budget

```
STAGING_URL: https://switch-api-staging.herokuapp.com
LIVE_URL: https://switchapi.azurewebsites.net
```

{% hint style="danger" %}
These requests are not in the current release
{% endhint %}

## Get Budget

<mark style="color:blue;">`GET`</mark> `https://switch-api-staging.herokuapp.com/user/budget`

This endpoint returns a user's budget

#### Headers

| Name        | Type   | Description                                                           |
| ----------- | ------ | --------------------------------------------------------------------- |
| auth\_token | string | The format for **auth\_token** is **Bearer&#x20;*****token\_string*** |

{% tabs %}
{% tab title="200 Budget retrieved successfully" %}

```
{
    "message": "Budget retrieved successfully",
    "data": {
        "total_kobo": "10000000.0",
        "allocations": [
            {
                "id": 309,
                "name": "my new car",
                "category": "transportation",
                "amount_kobo": "2500000.0"
            },
            {
                "id": 310,
                "name": "next ride",
                "category": "transportation",
                "amount_kobo": "500000.0"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Create Budget

<mark style="color:green;">`POST`</mark> `https://switch-api-staging.herokuapp.com/user/budget`

this endpoint helps users create a budget

#### Headers

| Name        | Type   | Description                                                           |
| ----------- | ------ | --------------------------------------------------------------------- |
| auth\_token | string | Teh format for **auth\_token** is **Bearer&#x20;*****token\_string*** |

#### Request Body

| Name                    | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ----------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| allocations\_attributes | string | <p>an array of objects that takes in <strong>name</strong>, <strong>category</strong> and <strong>amount\_kobo</strong><br>e.g <code>\[{</code><br> <code>name: “me”,</code><br> <code>category: “from the list of</code><em><strong><code>budget categories</code></strong></em><code>”,   amount\_kobo: “us”</code><br><code>},{</code><br> <code>name: “me”,</code> <br> <code>category: “from the list of</code><em><strong><code>budget categories</code></strong></em><code>”, amount\_kobo: “us”</code><br><code>}]</code></p> |
| total\_kobo             | string | total budget amount                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |

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

```
{
    "message": "Budget created successfully",
    "data": {
        "total_kobo": "0.0",
        "allocations": [
            {
                "id": 309,
                "name": "my new car",
                "category": "transportation",
                "amount_kobo": "2500000.0"
            },
            {
                "id": 310,
                "name": "next ride",
                "category": "transportation",
                "amount_kobo": "500000.0"
            }
        ]
    }
}
```

{% endtab %}

{% tab title="201 " %}

```
{
    "message": "Budget created successfully",
    "data": {
        "total_kobo": "10000000.0",
        "allocations": []
    }
}
```

{% endtab %}

{% tab title="400 Error" %}

```
{
    "message": "Error creating budget",
    "errors": {
        "total_kobo": [
            "can't be blank"
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Update User Budget

<mark style="color:purple;">`PATCH`</mark> `https://switch-api-staging.herokuapp.com/user/budget`

This endpoint allows user update their budget

#### Headers

| Name        | Type   | Description                                                           |
| ----------- | ------ | --------------------------------------------------------------------- |
| auth\_token | string | The format for **auth\_token** is **Bearer&#x20;*****token\_string*** |

#### Request Body

| Name        | Type   | Description                                                                                   |
| ----------- | ------ | --------------------------------------------------------------------------------------------- |
| total\_kobo | string | total budget amount                                                                           |
| allocations | string | takes in an arrqay of objects that takes in ***name***, ***category*** and ***amount\_kobo*** |

{% tabs %}
{% tab title="200 Budget updated successfully" %}

```
{
    "message": "Budget updated successfully",
    "data": {
        "total_kobo": "10000000.0",
        "allocations": [
            {
                "id": 309,
                "name": "my new car",
                "category": "transportation",
                "amount_kobo": "2500000.0"
            },
            {
                "id": 310,
                "name": "next ride",
                "category": "transportation",
                "amount_kobo": "500000.0"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Update user Budget

<mark style="color:orange;">`PUT`</mark> `https://switch-api-staging.herokuapp.com/user/budget`

This endpoint updates a user's budget

#### Headers

| Name        | Type   | Description                                                           |
| ----------- | ------ | --------------------------------------------------------------------- |
| auth\_token | string | The format for **auth\_token** is **Bearer&#x20;*****token\_string*** |

#### Request Body

| Name        | Type   | Description                                                                                 |
| ----------- | ------ | ------------------------------------------------------------------------------------------- |
| allocations | string | takes in a array of objects that takes in ***name***, ***category*** and ***amount\_kobo*** |
| total\_kobo | string | total budget amount                                                                         |

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

```
{
    "message": "Budget updated successfully",
    "data": {
        "total_kobo": "10000000.0",
        "allocations": [
            {
                "id": 309,
                "name": "my new car",
                "category": "transportation",
                "amount_kobo": "2500000.0"
            },
            {
                "id": 310,
                "name": "next ride",
                "category": "transportation",
                "amount_kobo": "500000.0"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Delete Budget

<mark style="color:red;">`DELETE`</mark> `https://switch-api-staging.herokuapp.com/user/budget`

This endpoint deletes a user's budget

#### Headers

| Name        | Type   | Description                                                           |
| ----------- | ------ | --------------------------------------------------------------------- |
| auth\_token | string | The format for **auth\_token** is **Bearer&#x20;*****token\_string*** |

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

```
{
    "message": "Budget deleted"
}
```

{% endtab %}
{% endtabs %}
