Creates a new invoice
import Fragment from '@fragment-dev/ts-node';
const client = new Fragment({
clientId: process.env['FRAGMENT_CLIENT_ID'],
clientSecret: process.env['FRAGMENT_CLIENT_SECRET'],
});
const response = await client.invoices.create(
{
invoice_id: 'invoice_2024_001',
line_items: [
{
amount: '1000',
currency_code: 'USD',
description: 'Professional services for January 2026',
product_id: 'prod_1234567890',
type: 'payout',
user: { id: 'user_abc123' }
}
]
}
);{
"data": {
"id": "inv_1234567890",
"workspace_id": "ws_1234567890",
"created": "2024-01-13T00:00:00Z",
"modified": "2024-01-13T00:00:00Z",
"version": 1,
"tags": [
{
"key": "region",
"value": "us-east"
}
]
}
}Lists all invoices for the workspace
import Fragment from '@fragment-dev/ts-node';
const client = new Fragment({
clientId: process.env['FRAGMENT_CLIENT_ID'],
clientSecret: process.env['FRAGMENT_CLIENT_SECRET'],
});
const response = await client.invoices.list();{
"data": [
{
"id": "inv_1234567890",
"workspace_id": "ws_1234567890",
"created": "2024-01-13T00:00:00Z",
"modified": "2024-01-13T00:00:00Z",
"version": 1,
"tags": [
{
"key": "region",
"value": "us-east"
}
]
}
]
}Gets the version history of an invoice
import Fragment from '@fragment-dev/ts-node';
const client = new Fragment({
clientId: process.env['FRAGMENT_CLIENT_ID'],
clientSecret: process.env['FRAGMENT_CLIENT_SECRET'],
});
const response = await client.invoices.listHistory('inv_1234567890');{
"data": [
{
"id": "inv_1234567890",
"workspace_id": "ws_1234567890",
"created": "2024-01-13T00:00:00Z",
"modified": "2024-01-13T00:00:00Z",
"version": 1,
"tags": [
{
"key": "region",
"value": "us-east"
}
]
}
]
}Gets an invoice by ID with balance details
import Fragment from '@fragment-dev/ts-node';
const client = new Fragment({
clientId: process.env['FRAGMENT_CLIENT_ID'],
clientSecret: process.env['FRAGMENT_CLIENT_SECRET'],
});
const response = await client.invoices.retrieve('inv_1234567890');{
"data": {
"id": "inv_1234567890",
"workspace_id": "ws_1234567890",
"created": "2024-01-13T00:00:00Z",
"modified": "2024-01-13T00:00:00Z",
"version": 1,
"tags": [
{
"key": "region",
"value": "us-east"
}
],
"users": [
{
"id": "user_ext_789",
"balances": []
}
],
"balances": [
{
"payins": {
"expected": "10000",
"actual": "5000",
"remaining": "5000"
},
"payouts": {
"expected": "10000",
"actual": "5000",
"remaining": "5000"
},
"net": {
"expected": "10000",
"actual": "5000",
"remaining": "5000"
},
"currency": "USD"
}
],
"payments": [
{
"amount": "150",
"currency": "USD",
"transaction": {
"id": "txn_dHhuX2ZyYWdfMDAx",
"external_id": "bank_txn_123",
"tags": [
{}
]
},
"type": "payin",
"posted": "2026-02-12T00:00:00.000Z",
"user": {
"id": "user_abc123",
"external_id": "user-ext-001"
}
}
]
}
}Updates an invoice
import Fragment from '@fragment-dev/ts-node';
const client = new Fragment({
clientId: process.env['FRAGMENT_CLIENT_ID'],
clientSecret: process.env['FRAGMENT_CLIENT_SECRET'],
});
const response = await client.invoices.update(
'inv_1234567890',
{
current_invoice_version: 3,
line_items: {
update: [
{
id: 'li_1234567890',
price: { amount: '2000' }
}
]
},
tags: { update: [{ key: 'region', value: 'eu-west-1' }] }
}
);{
"data": {
"id": "inv_1234567890",
"workspace_id": "ws_1234567890",
"created": "2024-01-13T00:00:00Z",
"modified": "2024-01-13T00:00:00Z",
"version": 1,
"tags": [
{
"key": "region",
"value": "us-east"
}
]
}
}Searches invoices
import Fragment from '@fragment-dev/ts-node';
const client = new Fragment({
clientId: process.env['FRAGMENT_CLIENT_ID'],
clientSecret: process.env['FRAGMENT_CLIENT_SECRET'],
});
const response = await client.invoices.search(
{
filter: { status: 'open' },
page_info: { limit: 20 }
}
);{
"data": {
"invoices": [
{
"id": "inv_1234567890",
"workspace_id": "ws_1234567890",
"created": "2024-01-13T00:00:00Z",
"modified": "2024-01-13T00:00:00Z",
"version": 1,
"tags": [
{}
],
"users": [
{}
],
"balances": [],
"payments": [
{}
]
}
],
"page_info": {}
}
}