JavaScript SDK - API Reference
This page explains how to use each of the available JavaScript SDK methods.
The ProductBadge object
This object represents a badge that has been created within your project. It contains all of a badges data such as it's ID, type, and any configured custom fields.
Attributes
- Name
id
- Type
- String
- Description
Unique identifier for the badge.
- Name
typeId
- Type
- String
- Description
The user defined identifier for the badges 'type'.
- Name
content
- Type
- Object
- Description
An object containing the values of the custom fields defined against the badges type schema.
The ProductBadge Object
{
"id": "4d28ffee-29a3-435a-8013-3e5e303e419b",
"typeId": "productCardBadge",
"content": {
"backgroundColour": "#22c55e",
"textColour": "#ffffff",
"text": "2 for $50"
}
}
The ProductBadgeQuery object
This object represents a query for a products badges.
Attributes
- Name
id
- Type
- Integer
- Required
- required
- Description
Product ID.
- Name
variantIds
- Type
- Array<Integer>
- Optional
- optional
- Description
An optional array of product variant IDs to retrieve badges for.
The ProductBadgeQuery Object
{
"id": 123,
"variantIds": [
456,
789
]
}
constructor
Instantiates the PromoBadgerClient.
Arguments
- Name
projectId
- Type
- String
- Required
- required
- Description
Your PromoBadger project ID.
- Name
context
- Type
- ContextObject
- Optional
- optional
- Description
The context for requests made using this client. ContextObject
import { PromoBadgerClient } from '@promobadger/sdk';
const client = new PromoBadgerClient({
projectId: 'YOUR_PROJECT_ID',
context: {
bigcommerce: {
channel: 123456,
currency: 'GBP'
}
}
});
getSingleProductBadges
Returns the badges for a single product.
Arguments
- Name
query
- Type
- ProductBadgeQuery
- Required
- required
- Description
The product query for the required badges. ProductBadgeQuery
Returns
- Name
query
- Type
- ProductBadgeQuery
- Description
The original query object. ProductBadgeQuery
- Name
badges
- Type
- Array<ProductBadge>
- Description
Array of product badges. ProductBadge
import { PromoBadgerClient } from '@promobadger/sdk';
const client = new PromoBadgerClient({
projectId: 'YOUR_PROJECT_ID'
});
const productBadges = await client.getSingleProductBadges({
id: 123
});
Response
{
query: { id: 123 },
badges: [
{
id: "4d28ffee-29a3-435a-8013-3e5e303e419b",
typeId: "productCardBadge",
content: {
backgroundColour: "#22c55e",
textColour: "#ffffff",
text: "2 for $50"
}
}
]
}
getProductBadges
Returns the badges for up to 100 products.
Arguments
- Name
query
- Type
- Object
- Required
- required
- Description
The product query for the required badges.
- Name
query.products
- Type
- Array<ProductBadgeQuery>
- Required
- required
- Description
Array of queries for badges. Limited to a maximum of 100 queries. ProductBadgeQuery
Returns
- Name
products
- Type
- Array<Object>
- Description
- Name
products[n].query
- Type
- ProductBadgeQuery
- Description
The original query object. ProductBadgeQuery
- Name
products[n].badges
- Type
- Array<ProductBadge>
- Description
Array of product badges. ProductBadge
import { PromoBadgerClient } from '@promobadger/sdk';
const client = new PromoBadgerClient({
projectId: 'YOUR_PROJECT_ID'
});
const productBadges = await client.getSingleProductBadges({
products: [
{ id: 123 },
{ id: 456, variantIds: [ 789 ] }
]
});
Response
{
products: [
{
query: { id: 123 },
badges: [
{
id: "4d28ffee-29a3-435a-8013-3e5e303e419b",
typeId: "productCardBadge",
content: {
backgroundColour: "#22c55e",
textColour: "#ffffff",
text: "2 for $50"
}
}
]
},
{
query: { id: 456, variantIds: [ 789 ] },
badges: [
{
id: "ea7d4021-94e1-426f-af4c-097eb475d2b5",
typeId: "productCardBadge",
content: {
backgroundColour: "#eab308",
textColour: "#ffffff",
text: "3 for 2"
}
}
]
}
]
}