1.2.1 • Published 1 year ago
@rantalainen/vero-api-client v1.2.1
Vero API Client
Vero third party API client. Vero API website: https://avoinomavero.vero.fi/APIPortal/
Installation
Add to project's package.json:
npm install @rantalainen/vero-api-client
Setup
Import to NodeJS project
const VeroApiClient = require('vero-api-client').VeroApiClient;
Import to TypeScript project
import { VeroApiClient } from 'vero-api-client';
Setup client with options
const veroClient = new VeroApiClient({
veroSoftwareId: '12345678_00',
certification, // Vero certification
privateKey // Private Key that matches certification
});
Full example
This API client inlcudes the most common functionalities as typed functions. Also included a common POST request, which allows requesting any endpoint directly with Vero API authorization. Available endpoints can be found in the API documentation.
Almost all APIs require Suomi.fi authentication. Call getTokens
before calling other functions for activating token. Token is valid for one hour. See full example below:
import { VeroApiClient } from 'vero-api-client';
import * as fs from 'fs';
async function main() {
try {
const certificate = fs.readFileSync('veroCertificate.csr');
const key = fs.readFileSync('privatekey.key');
const veroApiClient = new VeroApiClient({
veroSoftwareId: '12345678_00',
certification: certificate,
privateKey: key
});
const customerBusinessId = '9999999-9';
// Fetch Suomi.fi authorizations
const tokens = await veroApiClient.getTokens('1234567-8', [customerBusinessId]);
const authTokens = tokens.Tokens;
// Fetch letters from listLetters api
const letters = await veroApiClient.listLetters(authTokens[customerBusinessId], customerBusinessId, { numberOfLetters: 1 });
// Get letterNumber from letters list
const letterNumer = letters[0].LetterNumber;
// Get individual letter with letter number
const letterBuffer = await veroApiClient.getLetter(authTokens[customerBusinessId], customerBusinessId, letterNumer);
fs.writeFileSync('letter.pdf', letterBuffer);
} catch (e) {
console.error(e);
}
}
main();