Transactions

Retrieve transaction and payment data

Overview

The Transactions endpoints allow you to retrieve transaction and payment data. Transactions represent payment events that occur when agents make payments using payment intents. Each transaction includes details such as amount, merchant, date, status, and associated payment intent information. Transactions are read-only - they are automatically created when payments are processed.

Note: All endpoints require proper authentication. Make sure to include the Authorization: Bearer {access_token} header and the x-appid: {clientId} header in your requests.
Understanding Transactions: Transactions are created automatically when payments are processed through payment intents. Each transaction contains payment information including amount, currency, merchant details, payment intent (allocation) reference, status, and other relevant payment data. Transactions are read-only and cannot be directly updated through the API.

Get Transactions

GET /md/api/Expenses

Retrieves a list of transactions based on filter criteria. You can filter, sort, and paginate the results using query parameters.

Query Parameters

Use the filter query parameter to filter, sort, and paginate results. The filter should be a JSON object passed as a URL-encoded string.

Parameter Type Description
filter object (JSON) Filter, sorting, and pagination options. See filter options below.

Filter Options

The filter object supports the following properties:

Property Type Description
where object Filter conditions. See where clause examples below.
fields array Array of field names to include in the response
order string Sort order (e.g., "date DESC" or "amount ASC")
limit number Maximum number of results to return
skip number Number of results to skip (for pagination)
include array Related models to include (e.g., ["receipts", "transaction"])

Where Clause Examples

Common filter conditions for the where clause:

Field Example Description
ownerId {"ownerId": "user-id-123"} Filter by user who owns the transaction
companyId {"companyId": "company-id-123"} Filter by company ID
status {"status": "posted"} Filter by status: "posted", "pending", "declined", "canceled"
status (multiple) {"status": {"inq": ["posted", "pending"]}} Filter by multiple status values
date {"date": {"gte": "2024-01-01"}} Filter by date (greater than or equal)
date (range) {"date": {"between": ["2024-01-01", "2024-12-31"]}} Filter by date range
category {"category": "Travel"} Filter by transaction category/type
allocationId {"allocationId": "allocation-id-123"} Filter by payment intent (allocation) ID
merchantName {"merchantName": {"like": "%Starbucks%"}} Search by merchant name (case-insensitive partial match)

Example Requests

Get all posted transactions for a user in a date range:

const filter = {
  where: {
    ownerId: 'user-id-123',
    status: 'posted',
    date: {
      between: ['2024-01-01', '2024-12-31']
    }
  },
  order: 'date DESC',
  limit: 50
};

const filterParam = encodeURIComponent(JSON.stringify(filter));
const response = await fetch(`https://sandbox.custodia-tech.com/md/api/Expenses?filter=${filterParam}`, {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'x-appid': clientId
  }
});

const transactions = await response.json();

Get transactions with receipts included:

const filter = {
  where: {
    ownerId: 'user-id-123',
    status: {inq: ['posted', 'pending']}
  },
  include: ['receipts'],
  order: 'date DESC',
  limit: 100
};

const filterParam = encodeURIComponent(JSON.stringify(filter));
const response = await fetch(`https://sandbox.custodia-tech.com/md/api/Expenses?filter=${filterParam}`, {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'x-appid': clientId
  }
});

const transactions = await response.json();

Get transactions by category and amount:

const filter = {
  where: {
    ownerId: 'user-id-123',
    category: 'Travel',
    amount: {gte: 100}
  },
  order: 'amount DESC'
};

const filterParam = encodeURIComponent(JSON.stringify(filter));
const response = await fetch(`https://sandbox.custodia-tech.com/md/api/Expenses?filter=${filterParam}`, {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'x-appid': clientId
  }
});

const transactions = await response.json();

Response

Success Response (200 OK)

[
  {
    "id": "transaction-id-123",
    "ownerId": "user-id-123",
    "companyId": "company-id-123",
    "status": "posted",
    "date": "2024-01-15T10:30:00.000Z",
    "amount": 45.50,
    "currency": "USD",
    "amountInLocalCurrency": 45.50,
    "settlementAmount": 45.50,
    "settlementCurrency": "USD",
    "merchantName": "Starbucks",
    "category": "Meals",
    "allocationId": "allocation-id-456",
    "purpose": "Coffee meeting",
    "receiptRequired": true,
    "isSplit": false,
    "created": "2024-01-15T10:30:00.000Z",
    "modified": "2024-01-15T10:30:00.000Z"
  },
  {
    "id": "transaction-id-789",
    "ownerId": "user-id-123",
    "companyId": "company-id-123",
    "status": "pending",
    "date": "2024-01-16T14:20:00.000Z",
    "amount": 250.00,
    "currency": "USD",
    "amountInLocalCurrency": 250.00,
    "settlementAmount": 250.00,
    "settlementCurrency": "USD",
    "merchantName": "United Airlines",
    "category": "Travel",
    "allocationId": "allocation-id-789",
    "purpose": "Business trip",
    "receiptRequired": true,
    "isSplit": false,
    "created": "2024-01-16T14:20:00.000Z",
    "modified": "2024-01-16T14:20:00.000Z"
  }
]

Get Transaction by ID

GET /md/api/Expenses/{transactionId}

Retrieves detailed information about a specific transaction by its ID.

Path Parameters

Parameter Type Required Description
transactionId string Yes The unique identifier of the transaction

Query Parameters

Parameter Type Description
filter object (JSON) Optional filter to specify which fields to include or related models (e.g., {"fields": ["id", "amount", "status", "date"], "include": ["receipts"]})

Example Request

Using cURL:

curl -X GET "https://sandbox.custodia-tech.com/md/api/Expenses/transaction-id-123?filter=%7B%22include%22%3A%5B%22receipts%22%5D%7D" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "x-appid: YOUR_CLIENT_ID"

Using JavaScript (fetch):

const transactionId = 'transaction-id-123';

const filter = {
  include: ['receipts', 'transaction']
};

const filterParam = encodeURIComponent(JSON.stringify(filter));
const response = await fetch(`https://sandbox.custodia-tech.com/md/api/Expenses/${transactionId}?filter=${filterParam}`, {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'x-appid': clientId
  }
});

const transaction = await response.json();

Response

Success Response (200 OK)

  {
    "id": "transaction-id-123",
  "ownerId": "user-id-123",
  "companyId": "company-id-123",
  "status": "posted",
  "date": "2024-01-15T10:30:00.000Z",
  "amount": 45.50,
  "currency": "USD",
  "amountInLocalCurrency": 45.50,
  "settlementAmount": 45.50,
  "settlementCurrency": "USD",
  "merchantName": "Starbucks",
  "merchantCategory": "Restaurants",
  "category": "Meals",
  "allocationId": "allocation-id-456",
  "budgetAllocationId": "budget-allocation-id",
  "purpose": "Coffee meeting",
  "receiptRequired": true,
  "isSplit": false,
  "costCenterId": "cost-center-id",
  "glAccountCode": "6001",
      "receipts": [
        {
          "id": "receipt-id-123",
          "expenseId": "transaction-id-123",
      "mimeType": "image/jpeg",
      "url": "https://storage.example.com/receipts/receipt-id-123.jpg"
    }
  ],
  "created": "2024-01-15T10:30:00.000Z",
  "modified": "2024-01-15T10:30:00.000Z"
}
Note: Transactions are read-only. They are automatically created when payments are processed through payment intents. You cannot modify transactions directly through the API.

Error Responses

All endpoints may return the following error responses:

Status Code Description Solution
401 Unauthorized Invalid or missing access token Verify your access token is valid and included in the Authorization header
400 Bad Request Invalid filter parameters Check that your filter JSON is properly formatted and valid
404 Not Found Transaction not found Verify the transaction ID is correct and exists for your company
403 Forbidden Insufficient permissions Verify your access token has the required scopes and permissions to view transactions