JavaScript SDK - How to Use

Please follow the below instructions to install and integrate PromoBadger in your project using our official JavaScript SDK.

1. Install NPM package

Install the @promobadger/sdk NPM package by running one of the following commands:

# Yarn
yarn add @promobadger/sdk

# NPM
npm install @promobadger/sdk

2. Import and create the PromoBadger client

import { PromoBadgerClient } from '@promobadger/sdk';

const client = new PromoBadgerClient({
  projectId: 'YOUR_PROJECT_ID'
});

3. Retrieve badges

// Get badges for a specific product
await client.getSingleProductBadges({ id: 123 });

// Get badges for specific variant of an individual product
await client.getSingleProductBadges({
  id: 123,
  variantIds: [ 456 ]
});

// Get badges for multiple products
await client.getProductBadges({
  products: [
    { id: 123 },
    { id: 456, variantIds: [ 789 ] }
  ]
});