Skip to content

User - Expenses ​

Base URL: https://your-domain.com

Admin endpoints for managing expenses. All endpoints require admin/staff authentication.


Fetch All Expenses ​

Retrieve all expense records with optional filters.

PropertyValue
EndpointFetch All Expenses
MethodGET
URL/api/v1/expenses
AuthenticationBearer Token

Request Headers:

HeaderValueRequired
Acceptapplication/jsonYes
AuthorizationBearer your-auth-tokenYes

Query Parameters:

ParameterTypeRequiredDescription
from_datedateNoStart date filter
to_datedateNoEnd date filter
category_idintegerNoFilter by category

Success Response (200 OK):

json
{
    "success": true,
    "data": [
        {
            "id": 1,
            "category_id": 1,
            "category_name": "Office Supplies",
            "amount": 5000,
            "description": "Printer paper and ink",
            "created_by": "Admin",
            "created_at": "2024-01-15 10:30:00"
        }
    ],
    "total": 25000
}

Code Examples:

bash
curl -X GET "https://your-domain.com/api/v1/expenses?from_date=2025-01-01" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer your-auth-token"
php
<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client(['base_uri' => 'https://your-domain.com']);

$response = $client->request('GET', '/api/v1/expenses', [
    'headers' => [
        'Accept'        => 'application/json',
        'Authorization' => 'Bearer your-auth-token',
    ],
    'query' => [
        'from_date' => '2025-01-01',
    ],
]);

$data = json_decode($response->getBody(), true);
print_r($data);
javascript
const BASE_URL = 'https://your-domain.com';
const TOKEN = 'your-auth-token';

const params = new URLSearchParams({
  from_date: '2025-01-01',
});

const response = await fetch(`${BASE_URL}/api/v1/expenses?${params}`, {
  method: 'GET',
  headers: {
    Accept: 'application/json',
    Authorization: `Bearer ${TOKEN}`,
  },
});

const data = await response.json();
console.log(data);
python
import requests

BASE_URL = "https://your-domain.com"
TOKEN = "your-auth-token"

response = requests.get(
    f"{BASE_URL}/api/v1/expenses",
    headers={
        "Accept": "application/json",
        "Authorization": f"Bearer {TOKEN}",
    },
    params={
        "from_date": "2025-01-01",
    },
)

data = response.json()
print(data)
go
package main

import (
	"fmt"
	"io"
	"net/http"
	"net/url"
)

const baseURL = "https://your-domain.com"
const token = "your-auth-token"

func main() {
	endpoint := baseURL + "/api/v1/expenses"

	q := url.Values{}
	q.Set("from_date", "2025-01-01")
	endpoint += "?" + q.Encode()

	req, _ := http.NewRequest("GET", endpoint, nil)
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Authorization", "Bearer "+token)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	fmt.Println(resp.StatusCode, string(body))
}
rust
use reqwest::Client;

const BASE_URL: &str = "https://your-domain.com";
const TOKEN: &str = "your-auth-token";

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = Client::new();

    let response = client
        .get(format!("{BASE_URL}/api/v1/expenses"))
        .header("Accept", "application/json")
        .bearer_auth(TOKEN)
        .query(&[
            ("from_date", "2025-01-01"),
        ])
        .send()
        .await?;

    let data: serde_json::Value = response.json().await?;
    println!("{data:#}");
    Ok(())
}

Fetch Expense Categories ​

Retrieve all expense categories.

PropertyValue
EndpointFetch Expense Categories
MethodGET
URL/api/v1/expenses/categories
AuthenticationBearer Token

Success Response (200 OK):

json
{
    "success": true,
    "data": [
        {"id": 1, "name": "Office Supplies"},
        {"id": 2, "name": "Utilities"},
        {"id": 3, "name": "Equipment"}
    ]
}

Code Examples:

bash
curl -X GET "https://your-domain.com/api/v1/expenses/categories" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer your-auth-token"
php
<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client(['base_uri' => 'https://your-domain.com']);

$response = $client->request('GET', '/api/v1/expenses/categories', [
    'headers' => [
        'Accept'        => 'application/json',
        'Authorization' => 'Bearer your-auth-token',
    ],
]);

$data = json_decode($response->getBody(), true);
print_r($data);
javascript
const BASE_URL = 'https://your-domain.com';
const TOKEN = 'your-auth-token';

const response = await fetch(`${BASE_URL}/api/v1/expenses/categories`, {
  method: 'GET',
  headers: {
    Accept: 'application/json',
    Authorization: `Bearer ${TOKEN}`,
  },
});

const data = await response.json();
console.log(data);
python
import requests

BASE_URL = "https://your-domain.com"
TOKEN = "your-auth-token"

response = requests.get(
    f"{BASE_URL}/api/v1/expenses/categories",
    headers={
        "Accept": "application/json",
        "Authorization": f"Bearer {TOKEN}",
    },
)

data = response.json()
print(data)
go
package main

import (
	"fmt"
	"io"
	"net/http"
)

const baseURL = "https://your-domain.com"
const token = "your-auth-token"

func main() {
	endpoint := baseURL + "/api/v1/expenses/categories"

	req, _ := http.NewRequest("GET", endpoint, nil)
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Authorization", "Bearer "+token)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	fmt.Println(resp.StatusCode, string(body))
}
rust
use reqwest::Client;

const BASE_URL: &str = "https://your-domain.com";
const TOKEN: &str = "your-auth-token";

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = Client::new();

    let response = client
        .get(format!("{BASE_URL}/api/v1/expenses/categories"))
        .header("Accept", "application/json")
        .bearer_auth(TOKEN)
        .send()
        .await?;

    let data: serde_json::Value = response.json().await?;
    println!("{data:#}");
    Ok(())
}

Fetch Expense ​

Retrieve details of a specific expense.

PropertyValue
EndpointFetch Expense
MethodGET
URL/api/v1/expenses/{id}
AuthenticationBearer Token

Success Response (200 OK):

json
{
    "success": true,
    "data": {
        "id": 1,
        "category_id": 1,
        "category_name": "Office Supplies",
        "amount": 5000,
        "description": "Printer paper and ink",
        "receipt_url": null,
        "created_by": "Admin",
        "created_at": "2024-01-15 10:30:00"
    }
}

Code Examples:

bash
curl -X GET "https://your-domain.com/api/v1/expenses/1" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer your-auth-token"
php
<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client(['base_uri' => 'https://your-domain.com']);

$expenseId = 1;

$response = $client->request('GET', "/api/v1/expenses/{$expenseId}", [
    'headers' => [
        'Accept'        => 'application/json',
        'Authorization' => 'Bearer your-auth-token',
    ],
]);

$data = json_decode($response->getBody(), true);
print_r($data);
javascript
const BASE_URL = 'https://your-domain.com';
const TOKEN = 'your-auth-token';

const expenseId = 1;

const response = await fetch(`${BASE_URL}/api/v1/expenses/${expenseId}`, {
  method: 'GET',
  headers: {
    Accept: 'application/json',
    Authorization: `Bearer ${TOKEN}`,
  },
});

const data = await response.json();
console.log(data);
python
import requests

BASE_URL = "https://your-domain.com"
TOKEN = "your-auth-token"

expense_id = 1

response = requests.get(
    f"{BASE_URL}/api/v1/expenses/{expense_id}",
    headers={
        "Accept": "application/json",
        "Authorization": f"Bearer {TOKEN}",
    },
)

data = response.json()
print(data)
go
package main

import (
	"fmt"
	"io"
	"net/http"
	"strconv"
)

const baseURL = "https://your-domain.com"
const token = "your-auth-token"

func main() {
	expenseId := 1
	endpoint := baseURL + "/api/v1/expenses/" + strconv.Itoa(expenseId)

	req, _ := http.NewRequest("GET", endpoint, nil)
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Authorization", "Bearer "+token)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	fmt.Println(resp.StatusCode, string(body))
}
rust
use reqwest::Client;

const BASE_URL: &str = "https://your-domain.com";
const TOKEN: &str = "your-auth-token";

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = Client::new();
    let expense_id = 1;

    let response = client
        .get(format!("{BASE_URL}/api/v1/expenses/{expense_id}"))
        .header("Accept", "application/json")
        .bearer_auth(TOKEN)
        .send()
        .await?;

    let data: serde_json::Value = response.json().await?;
    println!("{data:#}");
    Ok(())
}

Create Expense ​

Record a new expense.

PropertyValue
EndpointCreate Expense
MethodPOST
URL/api/v1/expenses
AuthenticationBearer Token

Request Body:

json
{
    "isp_id": 1,
    "branch_id": 1,
    "user_id": 1,
    "category_id": 1,
    "amount": 5000,
    "description": "Office supplies"
}
ParameterTypeRequiredDescription
category_idintegerYesExpense category ID
amountdecimalYesExpense amount
descriptionstringNoExpense description

Success Response (201 Created):

json
{
    "success": true,
    "message": "Expense recorded successfully",
    "data": {
        "id": 1
    }
}

Code Examples:

bash
curl -X POST "https://your-domain.com/api/v1/expenses" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-auth-token" \
  -d '{
    "isp_id": 1,
    "branch_id": 1,
    "user_id": 1,
    "category_id": 1,
    "amount": 5000,
    "description": "Office supplies"
  }'
php
<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client(['base_uri' => 'https://your-domain.com']);

$response = $client->request('POST', '/api/v1/expenses', [
    'headers' => [
        'Accept'        => 'application/json',
        'Authorization' => 'Bearer your-auth-token',
    ],
    'json' => [
        'isp_id'      => 1,
        'branch_id'   => 1,
        'user_id'     => 1,
        'category_id' => 1,
        'amount'      => 5000,
        'description' => 'Office supplies',
    ],
]);

$data = json_decode($response->getBody(), true);
print_r($data);
javascript
const BASE_URL = 'https://your-domain.com';
const TOKEN = 'your-auth-token';

const response = await fetch(`${BASE_URL}/api/v1/expenses`, {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
    Authorization: `Bearer ${TOKEN}`,
  },
  body: JSON.stringify({
    isp_id: 1,
    branch_id: 1,
    user_id: 1,
    category_id: 1,
    amount: 5000,
    description: 'Office supplies',
  }),
});

const data = await response.json();
console.log(data);
python
import requests

BASE_URL = "https://your-domain.com"
TOKEN = "your-auth-token"

response = requests.post(
    f"{BASE_URL}/api/v1/expenses",
    headers={
        "Accept": "application/json",
        "Authorization": f"Bearer {TOKEN}",
    },
    json={
        "isp_id": 1,
        "branch_id": 1,
        "user_id": 1,
        "category_id": 1,
        "amount": 5000,
        "description": "Office supplies",
    },
)

data = response.json()
print(data)
go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

const baseURL = "https://your-domain.com"
const token = "your-auth-token"

func main() {
	endpoint := baseURL + "/api/v1/expenses"

	payload, _ := json.Marshal(map[string]any{
		"isp_id":      1,
		"branch_id":   1,
		"user_id":     1,
		"category_id": 1,
		"amount":      5000,
		"description": "Office supplies",
	})
	req, _ := http.NewRequest("POST", endpoint, bytes.NewBuffer(payload))
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer "+token)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	fmt.Println(resp.StatusCode, string(body))
}
rust
use reqwest::Client;
use serde_json::json;

const BASE_URL: &str = "https://your-domain.com";
const TOKEN: &str = "your-auth-token";

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = Client::new();

    let response = client
        .post(format!("{BASE_URL}/api/v1/expenses"))
        .header("Accept", "application/json")
        .bearer_auth(TOKEN)
        .json(&json!({
            "isp_id": 1,
            "branch_id": 1,
            "user_id": 1,
            "category_id": 1,
            "amount": 5000,
            "description": "Office supplies"
        }))
        .send()
        .await?;

    let data: serde_json::Value = response.json().await?;
    println!("{data:#}");
    Ok(())
}

Update Expense ​

Update an existing expense record.

PropertyValue
EndpointUpdate Expense
MethodPUT
URL/api/v1/expenses/{id}
AuthenticationBearer Token

Request Body:

json
{
    "amount": 6000,
    "description": "Updated description"
}

Success Response (200 OK):

json
{
    "success": true,
    "message": "Expense updated successfully"
}

Code Examples:

bash
curl -X PUT "https://your-domain.com/api/v1/expenses/1" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-auth-token" \
  -d '{
    "amount": 6000,
    "description": "Updated description"
  }'
php
<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client(['base_uri' => 'https://your-domain.com']);

$expenseId = 1;

$response = $client->request('PUT', "/api/v1/expenses/{$expenseId}", [
    'headers' => [
        'Accept'        => 'application/json',
        'Authorization' => 'Bearer your-auth-token',
    ],
    'json' => [
        'amount'      => 6000,
        'description' => 'Updated description',
    ],
]);

$data = json_decode($response->getBody(), true);
print_r($data);
javascript
const BASE_URL = 'https://your-domain.com';
const TOKEN = 'your-auth-token';

const expenseId = 1;

const response = await fetch(`${BASE_URL}/api/v1/expenses/${expenseId}`, {
  method: 'PUT',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
    Authorization: `Bearer ${TOKEN}`,
  },
  body: JSON.stringify({
    amount: 6000,
    description: 'Updated description',
  }),
});

const data = await response.json();
console.log(data);
python
import requests

BASE_URL = "https://your-domain.com"
TOKEN = "your-auth-token"

expense_id = 1

response = requests.put(
    f"{BASE_URL}/api/v1/expenses/{expense_id}",
    headers={
        "Accept": "application/json",
        "Authorization": f"Bearer {TOKEN}",
    },
    json={
        "amount": 6000,
        "description": "Updated description",
    },
)

data = response.json()
print(data)
go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"strconv"
)

const baseURL = "https://your-domain.com"
const token = "your-auth-token"

func main() {
	expenseId := 1
	endpoint := baseURL + "/api/v1/expenses/" + strconv.Itoa(expenseId)

	payload, _ := json.Marshal(map[string]any{
		"amount":      6000,
		"description": "Updated description",
	})
	req, _ := http.NewRequest("PUT", endpoint, bytes.NewBuffer(payload))
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer "+token)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	fmt.Println(resp.StatusCode, string(body))
}
rust
use reqwest::Client;
use serde_json::json;

const BASE_URL: &str = "https://your-domain.com";
const TOKEN: &str = "your-auth-token";

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = Client::new();
    let expense_id = 1;

    let response = client
        .put(format!("{BASE_URL}/api/v1/expenses/{expense_id}"))
        .header("Accept", "application/json")
        .bearer_auth(TOKEN)
        .json(&json!({
            "amount": 6000,
            "description": "Updated description"
        }))
        .send()
        .await?;

    let data: serde_json::Value = response.json().await?;
    println!("{data:#}");
    Ok(())
}

Delete Expense ​

Delete an expense record.

PropertyValue
EndpointDelete Expense
MethodDELETE
URL/api/v1/expenses/{id}
AuthenticationBearer Token

Success Response (200 OK):

json
{
    "success": true,
    "message": "Expense deleted successfully"
}

Code Examples:

bash
curl -X DELETE "https://your-domain.com/api/v1/expenses/1" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer your-auth-token"
php
<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client(['base_uri' => 'https://your-domain.com']);

$expenseId = 1;

$response = $client->request('DELETE', "/api/v1/expenses/{$expenseId}", [
    'headers' => [
        'Accept'        => 'application/json',
        'Authorization' => 'Bearer your-auth-token',
    ],
]);

$data = json_decode($response->getBody(), true);
print_r($data);
javascript
const BASE_URL = 'https://your-domain.com';
const TOKEN = 'your-auth-token';

const expenseId = 1;

const response = await fetch(`${BASE_URL}/api/v1/expenses/${expenseId}`, {
  method: 'DELETE',
  headers: {
    Accept: 'application/json',
    Authorization: `Bearer ${TOKEN}`,
  },
});

const data = await response.json();
console.log(data);
python
import requests

BASE_URL = "https://your-domain.com"
TOKEN = "your-auth-token"

expense_id = 1

response = requests.delete(
    f"{BASE_URL}/api/v1/expenses/{expense_id}",
    headers={
        "Accept": "application/json",
        "Authorization": f"Bearer {TOKEN}",
    },
)

data = response.json()
print(data)
go
package main

import (
	"fmt"
	"io"
	"net/http"
	"strconv"
)

const baseURL = "https://your-domain.com"
const token = "your-auth-token"

func main() {
	expenseId := 1
	endpoint := baseURL + "/api/v1/expenses/" + strconv.Itoa(expenseId)

	req, _ := http.NewRequest("DELETE", endpoint, nil)
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Authorization", "Bearer "+token)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	fmt.Println(resp.StatusCode, string(body))
}
rust
use reqwest::Client;

const BASE_URL: &str = "https://your-domain.com";
const TOKEN: &str = "your-auth-token";

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = Client::new();
    let expense_id = 1;

    let response = client
        .delete(format!("{BASE_URL}/api/v1/expenses/{expense_id}"))
        .header("Accept", "application/json")
        .bearer_auth(TOKEN)
        .send()
        .await?;

    let data: serde_json::Value = response.json().await?;
    println!("{data:#}");
    Ok(())
}

www.onezeroart.com