Products

Fetching a list of products

fetchProducts returns a Query object with a list of products or undefined if the query fails.

const products = await client.fetchProducts(filters, order, count, after);

Parameters

(optional) filters: ProductFilter

Filter products based on set criteria. Defaults to {}.

type ProductFilter = {
  collections?: IdType[];
  categories?: IdType[];
  stockAvailability?: ProductStockAvailability; // "IN_STOCK" | "OUT_OF_STOCK"
  search?: string;
  seller?: IdType;
  price?: PriceRange;
};

(optional) order: OrderType<ProductOrderField>

Order the result. Defaults to { field: "PUBLISHED", direction: "DESC" }.

const order = {
    field: "PUBLISHED", // "NAME" | "PRICE" | "MINIMAL_PRICE" | "DATE" | "TYPE" | "PUBLISHED" | "PUBLICATION_DATE" | "POPULARITY_RANK"
    direction: "DESC"
};

(optional) count: number

Number of products to fetch. Defaults to 20.

(optional) after: string

Cursor at which to start querying. Can be obtained from _cursor property of each product. Defaults to null.

Fetch a single product

You can fetch a single product either by id or by slug.

By id

Fetch a single product by id. Returns Product on success or undefined on failure.

const product = await client.fetchProductById(id);

Parameters

id: IdType

id of a product.

By slug

Fetch a single product by slug. Returns Product on success or undefined on failure.

const product = await client.fetchProductBySlug(slug);

Parameters

slug: string

slug of a product.

ProductInstance object

Represents a single product.

{
    id: "UHJvZKWpcGo4MrQ=",
    name: "A random product",
    description: "<p>Random <strong>product</strong> description</p>",
    slug: "a-random-product",
    clientUrl: "https://www.random-store.com/random-product",
    category: ...,
    weight: null,
    thumbnail: {
        url: ...,
        alt: ""
    },
    images: [
        {
            url: ...,
            alt: ""
        }
    ],
    pricing: ...,
    isAvailable: true,
    variants: ...,
    collections: [],
    translation: null,
    seller: {
        id: "U2VsbGVyVHlwZToyMw==",
        name: "LiveMarket",
        displayName: "LiveMarket",
        avatar: {
            url: ...,
            alt: null
        },
        country: "PL",
        email: ...
    },
    sellingConditions: ...,
    displayName: "A Random Product",
    displayDescription: "<p>Random <strong>product</strong> description</p>",
    displayPrice: "PLN 14.99"
}

Properties

id: IdType

Id of the product.

name: string

Name of the product.

description: string

Description of the product.

slug: string

Slug of the product.

clientUrl: string

A URL for the product in the original store.

category: Category

Category of the product. May be null.

weight: Weight

Weight of the product. May be null.

See Weight for more details.

thumbnail: Image

Thumbnail of the product. May be null.

See Image for more details.

images: Image[]

Gallery of the product. May be null.

See Image for more details.

pricing: ProductPricing

Pricing of the product. May be null.

type ProductPricing = {
  onSale?: boolean;
  discount?: TaxedMoney;
  discountLocalCurrency?: TaxedMoney;
  priceRange?: TaxedMoneyRange;
  priceRangeUndiscounted?: TaxedMoneyRange;
  priceRangeLocalCurrency?: TaxedMoneyRange;
};

See TaxedMoney and TaxedMoneyRange for more details.

isAvailable: boolean

Is the product available? May be null.

variants: ProductVariantInstance[]

Variants of the product. May be null.

collections: Collection[]

Collections the product is in. May be null.

translation: ProductTranslation

Translation of product’s name and description. May be null.

seller: Seller

Seller of the product. May be null.

sellingConditions: SellingConditions

Selling conditions for the product. May be null.

type SellingConditions = {
  id: IdType;
  fulfillmentTime?: FulfillmentTime;
  returnPolicy?: ReturnPolicy;
  warranty?: WarrantyType;
};

type FulfillmentTime = {
  id: IdType;
  name: string;
  time: number;
};

type ReturnPolicyShipment = "SELLER" | "BUYER";

type ReturnPolicy = {
  id: IdType;
  name: string;
  description: string;
  time: number;
  returnShipment: ReturnPolicyShipment;
};

type WarrantyType = "SELLER" | "MANUFACTURER";

type Warranty = {
  id: IdType;
  name: string;
  time: number;
  warrantyType: WarrantyType;
};

(readonly) displayName: string

Returns translated name of the product or original name if the requested translation is not available.

(readonly) displayDescription: string

Returns translated description of the product or original description if the requested translation is not available.

(readonly) displayPrice: string | null

Formatted price of the product.

If you don’t like the way the price is formatted or you would like to introduce custom HTML syntax into it, check out pricing property and formatPrice / formatPriceRange.

ProductVariantInstance object

Products may have different attributes - like size, color etc. ProductVariant describes a single combination of these attributes.

Properties

id: IdType

Id of the variant.

name: string

Variant name.

sku: string

Variant SKU.

weight: Weight

Weight of this variant. May be null.

pricing: VariantPricing

Pricing for this variant. May be null.

type VariantPricing = {
  onSale?: boolean;
  discount?: TaxedMoney;
  discountLocalCurrency?: TaxedMoney;
  price?: TaxedMoney;
  priceUndiscounted?: TaxedMoney;
  priceLocalCurrency?: TaxedMoney;
};

images: Image[]

Images of this product variant. May be null.

See Image for more details.

translation: ProductTranslation

Contains translated name and description of the product.

quantityAvailable: number

Quantity of a product available for sale.

(readonly) displayName: string

Translated name of the product.