EUlabel
SDK

TypeScript SDK

Install and use the @eulabel/sdk package for TypeScript and JavaScript projects.

Installation

npm install @eulabel/sdk
pnpm add @eulabel/sdk
yarn add @eulabel/sdk

Initialization

import { EUlabel } from '@eulabel/sdk';

const client = new EUlabel({
  apiKey: process.env.EULABEL_API_KEY,
});

Products

Create a product

const product = await client.products.create({
  name: 'Quinta do Crasto Douro Red 2021',
  category: 'wine',
  brand: 'Quinta do Crasto',
  gtin: '5601234567890',
});

console.log(product.productId);
console.log(product.qrCodeUrl);

List products

const { products } = await client.products.list();

for (const product of products) {
  console.log(product.name, product.gtin);
}

Get a product

const product = await client.products.get('a1b2c3d4-...');

Passports

Create a passport

const passport = await client.passports.create({
  productId: 'a1b2c3d4-...',
  data: {
    productType: 'wine',
    colour: 'red',
    vintage: 2021,
    ingredients: ['Grapes (Touriga Nacional)', 'Sulphur Dioxide'],
    nutrition: {
      energyKj: 351,
      energyKcal: 84,
      fatG: 0,
      saturatedFatG: 0,
      carbohydratesG: 0.6,
      sugarsG: 0.3,
      proteinG: 0.1,
      saltG: 0,
      alcoholG: 13.5,
    },
    allergens: {
      containsSulphites: true,
      containsEgg: false,
      containsFish: false,
      containsMilk: false,
    },
    origin: { country: 'PT', region: 'Douro', designation: 'Douro DOC' },
    producers: [{ name: 'Quinta do Crasto', role: 'producer', country: 'PT' }],
  },
});

Retrieve a passport

const passport = await client.products.getPassport('a1b2c3d4-...');

Analytics

const analytics = await client.analytics.getProduct('a1b2c3d4-...', {
  start: '2026-01-01',
  end: '2026-03-14',
});

console.log(`Total scans: ${analytics.totalScans}`);
console.log(`Countries: ${analytics.uniqueCountries}`);

Error handling

import { EUlabel, EUlabelError } from '@eulabel/sdk';

try {
  await client.products.create({ name: 'Test', category: 'wine', brand: 'Test', gtin: 'invalid' });
} catch (error) {
  if (error instanceof EUlabelError) {
    console.error(error.type);    // "validation_error"
    console.error(error.message); // "Invalid GTIN check digit"
    console.error(error.param);   // "gtin"
  }
}

Webhook verification

import { EUlabel } from '@eulabel/sdk';

const isValid = client.webhooks.verify(
  requestBody,
  request.headers['x-eulabel-signature'],
  process.env.WEBHOOK_SECRET,
);

On this page