跳到主要内容

Retrieve billing and payment information

This example demonstrates how to read billing-related information in ONLYOFFICE DocSpace via the API: customer profile, balance by currency, current quota, available quotas, auto top-up settings, and supported currencies.

Before you start

  1. Replace https://yourportal.onlyoffice.com and YOUR_API_KEY with your actual DocSpace portal URL and API key. Ensure you have the necessary data and permissions to perform migration operations.
  2. Before you can make requests to the API, you need to authenticate. Check out the Personal access tokens page to learn how to obtain and use access tokens.
Full example
// Config
const API_HOST = 'https://yourportal.onlyoffice.com';
const API_KEY = 'your_api_key';

const HEADERS = { Authorization: API_KEY };

// Step 1: Customer info
async function getCustomerInfo() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/customerinfo`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get customer info: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const info = data?.response ?? {};
console.log('Customer Info:', info);
return info;
}

// Step 2: Customer balance
async function getCustomerBalance() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/customer/balance`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get balance: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const balance = data?.response ?? {};
console.log('Balance:');
for (const sub of balance.subAccounts ?? []) {
console.log(`- ${sub.currency}: ${sub.amount}`);
}
return balance;
}

// Step 3: Current quota
async function getCurrentQuota() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/quota`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get current quota: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const q = data?.response ?? {};
console.log(`Current Quota: ${q.title}, Trial: ${q.trial}, Due: ${q.dueDate}`);
return q;
}

// Step 4: Available quotas
async function getAvailableQuotas() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/quotas`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get available quotas: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const list = data?.response ?? [];
console.log('Available Quotas:');
for (const q of list) {
const price = q.price ?? {};
console.log(`- ${q.title} - ${price.value} ${price.isoCurrencySymbol}`);
}
return list;
}

// Step 5: Auto Top-Up settings
async function getTopupSettings() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/topupsettings`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get topup settings: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const settings = data?.settings ?? data?.response ?? {};
console.log('Auto Top-Up Settings:');
console.log(`- Enabled: ${settings.enabled}`);
console.log(`- Min Balance: ${settings.minBalance}`);
console.log(`- Up To: ${settings.upToBalance}`);
console.log(`- Currency: ${settings.currency}`);
console.log(`- Last Modified: ${settings.lastModified}`);
return settings;
}

// Step 6: Supported currencies
async function getSupportedCurrencies() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/currencies`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get currencies: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const list = data?.response ?? [];
console.log('Supported Currencies:');
for (const c of list) {
console.log(`- ${c.isoCurrencySymbol} - ${c.currencyNativeName}`);
}
return list;
}

// Run
(async () => {
await getCustomerInfo();
await getCustomerBalance();
await getCurrentQuota();
await getAvailableQuotas();
await getTopupSettings();
await getSupportedCurrencies();
})();

Step 1: Retrieve customer information

A GET request is sent to /api/2.0/portal/payment/customerinfo.

The API response includes:

  • Basic customer profile details.
  • Billing-related contact information.
async function getCustomerInfo() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/customerinfo`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get customer info: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const info = data?.response ?? {};
console.log('Customer Info:', info);
return info;
}

Step 2: Retrieve customer balance

A GET request is sent to /api/2.0/portal/payment/customer/balance.

The API response includes:

  • Account balances per currency.
  • Amount available in each subaccount.
async function getCustomerBalance() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/customer/balance`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get balance: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const balance = data?.response ?? {};
console.log('Balance:');
for (const sub of balance.subAccounts ?? []) {
console.log(`- ${sub.currency}: ${sub.amount}`);
}
return balance;
}

Step 3: Retrieve current quota

A GET request is sent to /api/2.0/portal/payment/quota.

The API response includes:

  • Current plan title.
  • Trial status.
  • Due date for renewal or expiration.
async function getCurrentQuota() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/quota`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get current quota: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const q = data?.response ?? {};
console.log(`Current Quota: ${q.title}, Trial: ${q.trial}, Due: ${q.dueDate}`);
return q;
}

Step 4: Retrieve available quotas

A GET request is sent to /api/2.0/portal/payment/quotas.

The API response includes:

  • List of available plans.
  • Price and currency for each plan.
async function getAvailableQuotas() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/quotas`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get available quotas: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const list = data?.response ?? [];
console.log('Available Quotas:');
for (const q of list) {
const price = q.price ?? {};
console.log(`- ${q.title} - ${price.value} ${price.isoCurrencySymbol}`);
}
return list;
}

Step 5: Retrieve auto top-up settings

A GET request is sent to /api/2.0/portal/payment/topupsettings.

  • The API response includes:
  • Auto top-up activation status.
  • Minimum balance threshold.
  • Target balance after top-up.
  • Currency and last modification date.
async function getTopupSettings() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/topupsettings`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get topup settings: ${res.status} - ${t}`);
return null;
}
const data = await res.json();

const settings = data?.settings ?? data?.response ?? {};
console.log('Auto Top-Up Settings:');
console.log(`- Enabled: ${settings.enabled}`);
console.log(`- Min Balance: ${settings.minBalance}`);
console.log(`- Up To: ${settings.upToBalance}`);
console.log(`- Currency: ${settings.currency}`);
console.log(`- Last Modified: ${settings.lastModified}`);
return settings;
}

Step 6: Retrieve supported currencies

A GET request is sent to /api/2.0/portal/payment/currencies.

The API response includes:

  • Supported ISO currency symbols.
  • Native currency names.
async function getSupportedCurrencies() {
const res = await fetch(`${API_HOST}/api/2.0/portal/payment/currencies`, { headers: HEADERS });
if (!res.ok) {
const t = await res.text();
console.log(`Failed to get currencies: ${res.status} - ${t}`);
return null;
}
const data = await res.json();
const list = data?.response ?? [];
console.log('Supported Currencies:');
for (const c of list) {
console.log(`- ${c.isoCurrencySymbol} - ${c.currencyNativeName}`);
}
return list;
}