Betalink Docs
API Reference

Get Transactions

Retrieve transactions for a company

Endpoint

GET /api/v1/companies/{cvr}/transactions

Description

Returns a paginated list of Mastercard disposition transactions for a specific company.

Authentication

Required - Include X-API-Key header

Path Parameters

ParameterTypeRequiredDescription
cvrstringYes8-digit Danish CVR number

Query Parameters

ParameterTypeRequiredDefaultDescription
limitintegerNo50Number of results per page (1-100)
afterstringNo-Cursor for fetching the next page
beforestringNo-Cursor for fetching the previous page

Request

curl -X GET "https://betalink.dev/api/v1/companies/12345678/transactions?limit=20" \
  -H "X-API-Key: your-api-key"

Response

Success (200 OK)

{
  "data": [
    {
      "id": "tx_abc123def456",
      "mastercardDeliveryFileId": "file_xyz789",
      "recordIndex": 42,
      "cvr": "12345678",
      "regNumber": "1234",
      "accountNumber": "0012345678",
      "transferType": "BS",
      "dispositionDate": "2024-06-15",
      "count": 1,
      "amountDkk": "1250.00",
      "rawLine": "BS1234567812340012345678...",
      "createdAt": "2024-06-15T08:00:00Z",
      "updatedAt": "2024-06-15T08:00:00Z",
      "filename": "MC_DISP_20240615_001.txt",
      "processedAt": "2024-06-15T08:30:00Z"
    }
  ],
  "meta": {
    "total": 847,
    "limit": 20,
    "hasMore": true
  },
  "_links": {
    "self": "/api/v1/companies/12345678/transactions?limit=20",
    "next": "/api/v1/companies/12345678/transactions?limit=20&after=tx_abc123def456",
    "prev": null
  }
}

Transaction Object

FieldTypeDescription
idstringUnique transaction identifier
mastercardDeliveryFileIdstringID of the source delivery file
recordIndexnumberPosition in the delivery file
cvrstringCompany CVR number
regNumberstringBank registration number
accountNumberstringBank account number
transferTypestringTransaction transfer type
dispositionDatestringDate of disposition (YYYY-MM-DD)
countnumberTransaction count
amountDkkstringAmount in DKK (decimal string)
rawLinestringRaw line from the PBS file
createdAtstring | nullISO 8601 creation timestamp
updatedAtstring | nullISO 8601 last update timestamp
filenamestringSource file name
processedAtstring | nullWhen the file was processed

Error Responses

401 Unauthorized

{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Invalid or missing API key"
  }
}

404 Not Found

{
  "error": {
    "code": "COMPANY_NOT_FOUND",
    "message": "No company found with CVR 12345678"
  }
}

Code Example

import { createBetalinkClient } from "@betalink/api-client";

const client = createBetalinkClient({
  baseUrl: "https://betalink.dev/api",
  apiKey: "your-api-key",
});

// Get transactions for a company
const response = await client.getCompanyTransactions("12345678", {
  limit: 50,
});

console.log(`Total transactions: ${response.meta.total}`);

for (const tx of response.data) {
  console.log(`${tx.dispositionDate}: ${tx.amountDkk} DKK`);
}

Fetching All Transactions

async function getAllTransactions(cvr: string) {
  const transactions = [];
  let after: string | undefined;

  do {
    const response = await client.getCompanyTransactions(cvr, {
      limit: 100,
      after,
    });
    transactions.push(...response.data);

    if (response.meta.hasMore && response.data.length > 0) {
      after = response.data[response.data.length - 1].id;
    } else {
      break;
    }
  } while (true);

  return transactions;
}

const allTx = await getAllTransactions("12345678");
console.log(`Fetched ${allTx.length} transactions`);

Calculating Totals

const response = await client.getCompanyTransactions("12345678");

const total = response.data.reduce(
  (sum, tx) => sum + parseFloat(tx.amountDkk),
  0
);

console.log(`Total amount: ${total.toFixed(2)} DKK`);

Filtering by Date

While the API doesn't support date filtering directly, you can filter client-side:

const response = await client.getCompanyTransactions("12345678", {
  limit: 100,
});

const june2024 = response.data.filter((tx) => {
  const date = new Date(tx.dispositionDate);
  return date.getFullYear() === 2024 && date.getMonth() === 5; // June
});

console.log(`June 2024 transactions: ${june2024.length}`);

On this page