NodeJS
Documentation for VatZen's NPM module
VatZen is Deprecated since January 2022 and API server will be shut down soon!
Source code is available on GitHub.
NodeJS helper to connect your backend with VatZen https://vatzen.com. Before using the module, we highly encourage you to check out our official documentation before using this module.

Installation

Module is published in NPM register and can be installed via npm or yarn as showed below:
1
npm install vatzen
Copied!
or
1
yarn add vatzen
Copied!

Documentation

For more extensive documentation, please visit our official docs at https://documentation.vatzen.com

General

Once you obtained your API key from VatZen Dashboard, you can start using the module. To get started quickly, simply import the module and pass the API Key. After initialization, you can already start calling endpoints:
1
import VatZen from 'vatzen';
2
3
const vatzenClient = new VatZen({ apiKey: 'YOUR_API_KEY' });
4
5
vatzenClient.rates
6
.getByCountryCode('DE')
7
.then(germanyVatRates => {
8
console.log(germanyVatRates);
9
})
10
.catch((e: ErrorEntity) => {
11
console.log('Something went wrong: ', e.errors.message);
12
});
Copied!
VatZen NPM module is TS-first and have a complete type-coverage, which is supported out-of-the-box.

General TypeScript Entities

1
// Available VAT Categories
2
enum VatCategory {
3
'audiobook' = 'audiobook',
4
'broadcasting' = 'broadcasting',
5
'ebook' = 'ebook',
6
'eperiodical' = 'eperiodical',
7
'eservice' = 'eservice',
8
'telecommunication' = 'telecommunication',
9
}
10
11
// Interface which describes country
12
interface CountryEntity {
13
code: string;
14
name: string;
15
local_name: string;
16
member_state: boolean;
17
}
18
19
// Pagination information
20
interface PaginationEntity {
21
total: number;
22
has_more: boolean;
23
}
24
25
// Available error types
26
enum ErrorTypes {
27
missing_api_key = 'missing_api_key',
28
invalid_api_key = 'invalid_api_key',
29
usage_limit_reached = 'usage_limit_reached',
30
invalid_input = 'invalid_input',
31
invalid_ip_address = 'invalid_ip_address',
32
could_not_resolve_ip = 'could_not_resolve_ip',
33
invalid_country_code = 'invalid_country_code',
34
invalid_amount = 'invalid_amount',
35
}
36
37
// Error returned fomr the server
38
export interface ErrorEntity {
39
statusCode: number;
40
success: false;
41
error: {
42
code: number;
43
type: ErrorTypes;
44
message: string;
45
};
46
}
Copied!

Rates

Before using the endpoint, you can familiarize yourself with our Rates endpoint documentation.
All the rates function are available inside VatZen object inside rates parameter. For example vatzen.rates.find.

Rate TypeScript Entity

1
interface RateEntity {
2
standard_rate: number;
3
currency: string;
4
country: CountryEntity;
5
categories: {
6
[categoryName in VatCategory]: number | undefined;
7
};
8
}
Copied!

All Rates

In order to obtain all the rates, you can use rates.getAll() function, which accepts optional options object with the following (also optional) keys:
key
type
description
limit
number
Limit for pagination
page
number
Page number, starting from 1
memberState
boolean
Response will be filtered by member states only
getAll usage example:
1
try {
2
const allRates = await vatzen.rates.getAll({ memberState: true }).rates;
3
console.log('Rates': allRates);
4
} catch (e: ErrorEntity) {
5
// getAll will throw an error if something went wrong
6
}
Copied!
Returns:
1
interface GetAllRatesResponse {
2
pagination: PaginationEntity;
3
rates: RateEntity[];
4
}
Copied!

Rate by Country Code

If you want to obtain the rate by known ISO Country Code, you can use rates.getByCountryCode function, which accepts country code string as a parameter. For example:
1
try {
2
const deVatRates = await vatzen.rates.getByCountryCode('DE');
3
console.log('Germany VAT Rates': deVatRates);
4
} catch (e: ErrorEntity) {
5
// getByCountryCode will throw an error if something went wrong
6
}
Copied!
Returns RateEntity.

Find Rate

You can use VatZen to lookup country rate using different parameters, such as country name, country code or ip address. In order to do that, you can use rates.find function, which accepts options object with the following properties:
key
type
description
countryCode
string
2 characters ISO country code
countryName
string
Country name, for example Germany
ipAddress
string
IP Address of your client which will be used to identify the country
useClientIp
boolean
If set to true, VatZen will extract ip address from the request
Example for using this function:
1
try {
2
const deVatRates = await vatzen.rates.find({ countryName: 'Germany' });
3
console.log('Germany VAT Rates': deVatRates);
4
} catch (e: ErrorEntity) {
5
// find will throw an error if something went wrong
6
}
Copied!
Returns RateEntity.

VAT Number Validation

Before using the endpoint, you can familiarize yourself with our Validations endpoint documentation.
All the rates function are available inside VatZen object inside validations parameter. For example vatzen.validations.validate.

Validation TypeScript Entity

1
export interface ValidationEntity {
2
id?: string;
3
consultation_number?: string;
4
requested: string;
5
created: string;
6
valid: boolean | null;
7
query: string;
8
country: CountryEntity;
9
company: null | {
10
name: string | null;
11
address: string | null;
12
};
13
pending: boolean;
14
valid_format: boolean;
15
requester: null | {
16
country_code: string;
17
vat_number: string;
18
};
19
}
Copied!

Validate VAT Number

VAT number validation is implemented inside validate function, which accepts only 1 parameter - vat number string. As the response, it returns the complete Validations entity.
Example:
1
try {
2
const validationResult = await vatzen.validations.validate('LU123455');
3
if (validationResult.valid) {
4
console.log('Validated company: ': validationResult.company.name);
5
}
6
} catch (e: ErrorEntity) {}
Copied!
Returns ValidationEntity.

Create Validation

If you want to validate VAT number and store the validation, you can use createValidation function, which accepts VAT number as a parameter and returns VAT Entity.
Example:
1
try {
2
const validationResult = await vatzen.validations.createValidation('LU123455');
3
if (validationResult.valid) {
4
console.log('Validated company: ': validationResult.company.name);
5
}
6
} catch (e: ErrorEntity) {}
Copied!
Returns ValidationEntity.

Get validation by id

Returns stored validation object by id. Implemented in getValidationById function.
1
try {
2
const validation = await vatzen.validations.getValidationById('dgy13wjbhbj342');
3
console.log('Fetched Validation:': validation);
4
} catch (e: ErrorEntity) {}
Copied!
Returns ValidationEntity.

Get all validation

If you want to fetch all validations, you can use getAll function, which accepts optional options object with the following optional parameters:
key
type
description
limit
number
Limit for pagination
page
number
Page number, starting from 1
Returns:
1
interface GetAllValidationsResponse {
2
pagination: PaginationEntity;
3
validations: ValidationEntity[];
4
}
Copied!

Prices Calculations

VAT prices calculations are implemented inside prices module in vatzen client, which you can access via vatzen.prices. Before using this endpoint, make sure to read our Official Prices Documentation.

Price TypeScript Entity

1
export interface PriceEntity {
2
id?: string;
3
amount: {
4
total_incl_vat: 0;
5
total_excl_vat: 0;
6
vat_amount: 0;
7
};
8
category: VatCategory;
9
vat_rate: 0;
10
country: CountryEntity;
11
requested: PriceCalculationRequest;
12
success: true;
13
}
Copied!

Calculate Price

Implemented via vatzen.prices.calculate function. Using this function, you can perform price calculation based on different parameters. If accepts options object, with 1 required fields: amount, and various option fields, which will be used to identify VAT rate.
key
type
description
amount
number
Amount for VAT calculation in cents
vatIncluded
boolean
Identifies if VAT already included in amount
category
VatCategory
VAT Category used for price calculations
countryCode
string
2 characters ISO country code
countryName
string
Country name, for example Germany
ipAddress
string
IP Address of your client which will be used to identify the country
useClientIp
boolean
If set to true, VatZen will extract ip address from the request
Example:
1
const calculatePriceForGermany = await vatzenClient.prices.calculate({
2
amount: 10000,
3
countryCode: 'DE',
4
category: VatCategory.audiobook,
5
});
6
console.log(
7
'100 EUR with VAT for AudioBooks in Germany: ',
8
Math.round(calculatePriceForGermany.amount.total_incl_vat / 100),
9
);
Copied!
Returns PriceEntity.

Create Price Calculation

If you want to calculate price and store the calculation, you can use createPriceCalculation function, which accepts the same parameters as calculate function.
Example:
1
const createdPriceForSpain = await vatzenClient.prices.createPriceCalculation(
2
{
3
amount: 10000,
4
countryCode: 'ES',
5
},
6
);
7
console.log('Created price ID: ', createdPriceForSpain.id);
Copied!
Returns PriceEntity.

Get Price Calculation by id

Returns stored price calculation object by id. Implemented in getPriceCalculationById function.
1
const retrievedPrice = await vatzenClient.prices.getPriceCalculationById(
2
createdPriceForSpain.id,
3
);
4
console.log('Retrieved price: ', retrievedPrice);
Copied!
Returns PriceEntity.

Get all price calculations

If you want to fetch all calculations you performed, you can use getAll function, which accepts optional options object with the following optional parameters:
key
type
description
limit
number
Limit for pagination
page
number
Page number, starting from 1
Returns:
1
interface GetAllPriceCalculationsResponse {
2
pagination: PaginationEntity;
3
validations: PriceEntity[];
4
}
Copied!