Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

cx-reports/api-client-typescript

Open more actions menu

Repository files navigation

TypeScript API Client for CxReports

NPM Version

This library allows you to connect to the CxReports API from your applications.

Installation

npm install @cx-reports/api-client

Example Usage

import { CxReportsClient } from "@cx-reports/api-client";

const client = new CxReportsClient({
  baseUrl: "[cx-reports-server-url]",
  authToken: "[your-personal-access-token]",
  defaultWorkspaceId: "[id or code of the workspace]",
  defaultTimezone: "UTC"
});

// export a report to PDF
let pdf = client.downloadPDF({ reportId: 123, params: {} });

// fetch all reports of type invoice
let reports = await client.getReports({ type: "invoice" });

// get all available report types
let types = await client.getReportTypes();

// get all available workspaces
let workspaces = await client.getWorkspaces();

// create a web token to authenticate iframe preview
let nonce = await client.createNonceAuthToken();

// get a preview URL of a report or report type
let url = client.getReportPreviewURL({
  reportType: "invoice",
  params: {},
  data: {},
  tmpDataId: 1
  nonce,
});

The current timezone of your server can be obtained using new Intl.DateTimeFormat().resolvedOptions().timeZone.

Examples

The examples folder provides the usage examples.

To set up your environment variables:

  1. Rename the .env.sample file to .env.
  2. Open the .env file in your text editor.
  3. Replace the placeholder values with your actual values.

License

MIT License

Contributors 2

  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.