@sledge-app/api

@sledge-app/api provides functions collections that you can use to work with Sledge's Server Side Fetching method, make sure to read more about Server Side Fetching prior to continuing working with this API.

Available functions :

getSledgeSession

This function can be used to get new user session.

getSledgeSession result can be saved to session as sledgeSession. Saved sledgeSession will be used for all @sledge-app/api request, including getSledgeSession request as well for lastSession.

See example

Anatomy

import { getSledgeSession } from "@sledge-app/api";
 
const sledgeSession = await getSledgeSession({
  lastSession: "",
  apiKey: "",
  instantSearchApiKey: "",
  userId: "",
  userEmail: "",
  userFullname: "",
});

API reference

lastSession

Fill with last saved sledgeSession from getSledgeSession

  • Type: undefined | any

apiKey

Fill with your own API Key

Your Shopify Admin › Apps › Sledge › General › API Key › API Key.

Or see the Using Backend - General - API Key for more information.

  • Type: string

instantSearchApiKey

Fill with your own Instant Search API Key

Your Shopify Admin › Apps › Sledge › General › API Key › Instant Search Key.

Or see the Using Backend - General - API Key for more information.

  • Type: string

userId

Fill with logged in user id

  • Type: string

userEmail

Fill with logged in user email

  • Type: string

userFullname

Fill with logged in user fullname

  • Type: string

getSledgeSettings

This function can be used to get data setting for each apps.

See example

Anatomy

import { getSledgeSettings } from "@sledge-app/api";
 
const sledgeSettings = await getSledgeSettings({
  sledgeSession: "",
});

API reference

sledgeSession

Fill with saved sledgeSession, from getSledgeSession

  • Type: any

getWishlist

This function can be used to get data wishlist for current user session or another user wishlist with share id.

See example

Anatomy

import { getWishlist } from "@sledge-app/api";
 
const wishlist = await getWishlist({
  sledgeSession: "",
  shareId: "",
});

API reference

sledgeSession

Fill with saved sledgeSession, from getSledgeSession

  • Type: any

shareId

Used for show another user wishlist who share links from wishlist pages. If not filled, getWishlist will return wishlist of current user session.

  • Type: string
  • Required: false

wishlistCheck

This function can be used for checking products is on wishlist or not.

See example

Anatomy

import { wishlistCheck } from "@sledge-app/api";
 
const wishlistChecked = await wishlistCheck({
  sledgeSession: "",
  productIds: [],
});

API reference

sledgeSession

Fill with saved sledgeSession, from getSledgeSession

  • Type: any

productIds

Fill with array of product IDs want to check

  • Type: array

getWishlistInfo

This function can be used for get data user wishlist info like share id for wishlist page and wishlist count for header menu.

See example

Anatomy

import { getWishlistInfo } from "@sledge-app/api";
 
const wishlistInfo = await getWishlistInfo({
  sledgeSession: "",
});

API reference

sledgeSession

Fill with saved sledgeSession, from getSledgeSession

  • Type: any

getProductsReviewInfo

This function can be used for get data reviews count and rating average of multiple products for Rating component.

See example

Anatomy

const reviews = await getProductsReviewInfo({
  sledgeSession: "",
  productIds: [],
});

API reference

sledgeSession

Fill with saved sledgeSession, from getSledgeSession

  • Type: any

productIds

Fill with array of product IDs want to check

  • Type: array

getReview

This function can be used for get reviews list of product to show on product detail page.

See example

Anatomy

import { getReview } from "@sledge-app/api";
 
const reviewList = await getReview({
  sledgeSession: "",
  productId: "",
});

API reference

sledgeSession

Fill with saved sledgeSession, from getSledgeSession

  • Type: any

productId

Fill with product ID want to show review list

  • Type: string

getResult

This function can be used for get search result for search page or product listing page.

See example

Anatomy

import { getResult } from "@sledge-app/api";
 
const searchResult = await getResult({
  sledgeSession: "",
  sledgeSettings: "",
  instantSearchApiKey: "",
  searchParams: "",
  keyword: "",
  collectionId: "",
  layoutType: "",
});

API reference

sledgeSession

Fill with saved sledgeSession, from getSledgeSession

  • Type: any

sledgeSettings

Fill with data setting from getSledgeSettings

  • Type: any

instantSearchApiKey

Fill with your own Instant Search API Key

Your Shopify Admin › Apps › Sledge › General › API Key › Instant Search Key.

Or see the Using Backend - General - API Key for more information.

  • Type: string

searchParams

Fill with object from url query string parameter

  • Type: object

keyword

Fill with typed search keyword from user

  • Type: string

collectionId

Fill with collection id if want to show result only for specific collection.
If collection id not filled result while return data from all collection.

  • Type: string

layoutType

Fill with default to return data for search result page, or fill with product-filter to return data for product listing page

  • Type: string

addToCartTrigger

This function can be used to save information for dashboard analytics about cart addition activities.

See example

Anatomy

React Version

import { addToCartTrigger } from '@sledge-app/api';
 
await addToCartTrigger({
  sourceApp: "",
  productId: "",
});

Vanilla JS Version

window.sledgeCommonModule.addToCartTrigger({
  sourceApp: "",
  productId: "",
});

API reference

sourceApp

Fill with name of app

  • Type:
    • 'wishlist'
    • 'instant-search'
    • 'recently-viewed'
    • 'related-product'
    • 'hand-picked'
    • 'new-arrival'
    • 'personalized-curated'

productId

Fill with product ID want to show review list

  • Type: string

productClickTrigger

This function can be used to save information for dashboard analytics about product click activities.

See example

Anatomy

React Version

import { productClickTrigger } from '@sledge-app/api';
 
await productClickTrigger({
  sourceApp: "",
  productId: "",
});

Vanilla JS Version

window.sledgeCommonModule.productClickTrigger({
  sourceApp: "",
  productId: "",
});

API reference

sourceApp

Fill with name of app

  • Type:
    • 'wishlist'
    • 'instant-search'
    • 'recently-viewed'
    • 'related-product'
    • 'hand-picked'
    • 'new-arrival'
    • 'personalized-curated'

productId

Fill with product ID want to show review list

  • Type: string

shopifyFormatMoney

This function can be used for money format handler.

Anatomy

React Version

import { shopifyFormatMoney } from '@sledge-app/api';
 
...
<div>
    {shopifyFormatMoney(price)}
</div>
...

Vanilla JS Version

window.sledgeCommonModule.shopifyFormatMoney(price)

API reference

price

Fill with your price data

  • Type: string | number

Learn more

Congratulations! Now that you've learned the @sledge-app/api API references, you can start integrating Sledge to your store. Useful resources about integrating Sledge :