Skip to content

Current product

This feature allows to get the current product passing the live id and a function that will be called everytime the product is updated. The code below shows a example subscribing and unsubscribing for recieve the udpates.

import { Metalives } from "metalives-sdk"
import dotenv from 'dotenv'

dotenv.config();

const client = new Metalives(process.env.SDK_TOKEN);

const setCurrentProduct = (currentProduct) => {
    console.log(currentProduct);
}

client.product.subscribeCurrentProduct(liveId, setCurrentProduct);
client.product.unsubscribeCurrentProduct();

Will be returned a object with the product id of current product, following the bwelow format:

{
    id: 'id of current product'
    ref: 'Product reference in marketplace'
}

Note: If there is not any product active in live, the values of id and ref will be 0.