Skip to content
guides

JavaScript SDK

Our JavaScript SDK is the easiest way to start making requests to the Topsort API.

Installation

The SDK works in any modern JavaScript environment, meaning browsers and most javascript runtimes (we are yet to support Deno).

Start by adding it to your dependencies:

Terminal window
# add topsort's sdk to your project
npm i @topsort/sdk

Usage

Now, let’s import the library and make a request.

It’s important to keep in mind that the api key is something you generally want to keep confidential. If you are making calls from the frontend, this cannot be avoided. In some cases, such as loading banners client-side this is not possible, but in most cases you should try to make auctions server-side.

import { TopsortClient, Auction } from "@topsort/sdk";
const auctionDetails: Auction = {
auctions: [
{
type: "listings",
slots: 3,
products: {
ids: ["product_1", "product_2"],
},
},
],
};
const config = {
// generate your api key in Topsort's dashboard - it should look some thing like this
// note: this is an invalid key and won't work, you need to replace it with your own
apiKey: "TSE_4S6o1g1CB5tyRENfhDMAn6viR7A5cy3j1JAR",
};
const topsortClient = new TopsortClient(config);
topsortClient
.createAuction(auctionDetails)
.then((result) => console.log(result))
.catch((error) => console.error(error));

This will create an auction with the given details. You can find more information about the available options in the documentation.

We work continuously on improving the SDK. If you find issues or have feature suggestions, open an issue!