Repository navigation
Getting Started
This page walks you through installing the Vendor SDK, configuring its endpoints, authenticating a vendor user and making the first call. By the end you will have a page that lists the signed-in vendor's products and updates the stock of one of them.
- A Selldone shop whose business model is marketplace, with at least one vendor. The marketplace owner creates vendors and approves vendor requests in the Selldone dashboard (see Vendor Panels and Marketplaces).
- A user who is a member of that vendor, and an access token for that user. Vendor-panel tokens use the
vendor-readandvendor-writescopes (see the scope list on Access Token). - The vendor ID.
GET /vendors(window.VAPI.GET_MY_VENDORS()) returns the vendors the user belongs to. - A browser application built with a bundler, and Node.js with npm or Yarn.
npm install @selldone/sdk-vendor @selldone/core-jsyarn add @selldone/sdk-vendor @selldone/core-jsAdd these tags to the page head:
<meta name="service-url" content="https://selldone.com">
<meta name="selldone-vapi" content="VENDOR_API_BASE_URL">| Meta tag | Read by | Purpose |
|---|---|---|
service-url |
SelldoneCore.Setup(), VendorSDK.Setup()
|
Main Selldone URL. Required; setup throws without it. |
selldone-vapi |
window.VAPI |
Base URL of every vendor API endpoint. Use the vendor API base URL of your Selldone environment. |
shop-prefix-address |
VendorSDK.Setup() |
Optional. Path used for the vendor_access_token cookie. |
csrf-token |
VendorSDK.Setup() |
Optional. Sent as X-CSRF-TOKEN. Without it, the console shows CSRF token not found!. |
If you cannot edit the page head, set the same keys on window.selldone_config before setup; Selldone Core reads
that object when a meta tag is missing.
VendorSDK.Setup() looks for the token in two places, in this order:
-
window.SelldoneUser.access_token: the SDK sends it asAuthorization: Bearer …and saves it in thevendor_access_tokencookie (throughwindow.$cookies, whichSelldoneCore.Setup()registers). - The
vendor_access_tokencookie from a previous visit.
window.SelldoneUser = {
access_token: ACCESS_TOKEN,
expires_in: EXPIRES_IN, // seconds, as returned with the token
};You can also set or replace the header at any time:
window.axios.defaults.headers.common["Authorization"] = `Bearer ${ACCESS_TOKEN}`;import { SelldoneCore } from "@selldone/core-js";
import { VendorSDK } from "@selldone/sdk-vendor";
SelldoneCore.Setup(); // registers window.$cookies, CDN and URL helpers
VendorSDK.Setup(); // registers window.VAPI and window.$vendorVendorSDK.Setup() configures window.axios (authorization, CSRF and the S-Referrer and S-Location headers),
creates the URL builder catalog window.VAPI, and creates window.$vendor with the page, product, category,
article and logistic namespaces.
const VENDOR_ID = 42;
// 1. List the vendor's products
const { products, total } = await window.$vendor.product.list(VENDOR_ID, 0, 25, {
products_only: true,
with_total: true,
});
console.log(`Vendor has ${total} products`);
// 2. Read one product with its variants and images
const { product } = await window.$vendor.product.getInfo(VENDOR_ID, products[0].id, 0, 10);
// 3. Update its stock
const { quantity } = await window.$vendor.product.setQuantity(VENDOR_ID, product.id, 40);Errors reject the promise with the API error body ({ error: true, error_msg, code }) or an Axios error:
try {
await window.$vendor.product.setQuantity(VENDOR_ID, PRODUCT_ID, 40);
} catch (error) {
console.warn(error?.error_msg ?? error);
}