NodeJS

Documentation for VatZen's NPM module

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:

npm install vatzen

or

yarn add vatzen

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:

import VatZen from 'vatzen';

const vatzenClient = new VatZen({ apiKey: 'YOUR_API_KEY' });

vatzenClient.rates
    .getByCountryCode('DE')
    .then(germanyVatRates => {
      console.log(germanyVatRates);
    })
    .catch((e: ErrorEntity) => {
      console.log('Something went wrong: ', e.errors.message);
    });

VatZen NPM module is TS-first and have a complete type-coverage, which is supported out-of-the-box.

General TypeScript Entities

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

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:

Returns:

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:

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:

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

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:

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:

Returns ValidationEntity.

Get validation by id

Returns stored validation object by id. Implemented in getValidationById function.

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:

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

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:

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:

Returns PriceEntity.

Get Price Calculation by id

Returns stored price calculation object by id. Implemented in getPriceCalculationById function.

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:

Last updated

Was this helpful?