Repository navigation
Getting Started
This page takes you from installation to your first community calls: loading a community with its categories and searching its posts. It covers both a storefront setup (the most common case) and a standalone page.
- A Selldone shop with a community, or use the main Selldone community (ID
1) to experiment. - A browser application built with a bundler, and Node.js with npm or Yarn.
- For actions on behalf of a member (posting, reacting, following), a signed-in customer session. In a storefront, the Storefront SDK handles this.
npm install @selldone/sdk-communityyarn add @selldone/sdk-communityThe package depends on @selldone/core-js, axios and lodash-es.
Add these tags to the page head:
<meta name="service-url" content="https://selldone.com">
<meta name="selldone-capi" content="https://capi.selldone.com">
<!-- Only needed for embed links (CommunityURLs.PostEmbedUrl) -->
<meta name="selldone-iframe" content="https://iframe.selldone.com">| Meta tag | Read by | Purpose |
|---|---|---|
selldone-capi |
window.CAPI |
Base URL of every community API route. |
service-url |
CommunityURLs and Selldone Core |
Main Selldone URL, used for links. |
selldone-iframe |
CommunityURLs.PostEmbedUrl() |
Base URL of embeddable posts. |
As with the other Selldone SDKs, you can provide the same keys on window.selldone_config instead of meta tags.
Set up the Storefront SDK first, then the Community SDK. This is the order used by the official Storefront:
import { StorefrontSDK } from "@selldone/sdk-storefront";
import { CapiCommunity } from "@selldone/sdk-community";
// ━━━ Storefront SDK (xapi) ━━━
StorefrontSDK.Setup();
// ━━━ Community SDK (capi) ━━━
CapiCommunity.Setup(); // Registers window.CAPI and window.$communityThe Storefront SDK initializes Selldone Core and puts the customer's Authorization header on window.axios. The
community requests use the same window.axios, so they are sent as the signed-in customer.
import { SelldoneCore } from "@selldone/core-js";
import { CapiCommunity } from "@selldone/sdk-community";
SelldoneCore.Setup();
CapiCommunity.Setup();
// Optional: act as a signed-in user
window.axios.defaults.headers.common["Authorization"] = `Bearer ${ACCESS_TOKEN}`;// Resolve the community of the current shop (or 1, the main Selldone community)
const communityId = window.$community.getCommunityID(shop);
const { community, categories, data } = await window.$community.getInfo(communityId);
console.log(community.title, categories.map((c) => c.title));getInfo accepts optional offset and days arguments that select the time window of the statistics returned in
data (the Components community layout uses offset = 0 and days = 7 by default).
let offset = 0;
const limit = 20;
const { posts, more } = await window.$community.post.searchPosts(communityId, offset, limit, "shipping");
// Load the next page while `more` is trueconst { data: feed } = await window.axios.get(window.CAPI.GET_COMMUNITY_FEED(communityId), {
params: { offset: 0, limit: 10 },
});
if (feed.error) console.warn(feed.error_msg);See Community API URL Builders for every route.