Skip to main content

Get Product Details using Slug

In this example use case, we will retrieve product details using a slug with the getProductDetailBySlug API. This guide demonstrates how to implement a headless commerce solution using the Fynd Platform SDK.

Prerequisites

  • Node.js v18↗ or later

  • Before you begin, collect the following credentials and identifiers from the Fynd Commerce platform for headless implementation:

    • Company ID
    • Client ID
    • Client Secret
    • Application ID

    These credentials establish the connection between your API calls and your Fynd Commerce account, ensuring secure and authenticated access to platform resources.

Obtaining Credentials

Follow these steps to retrieve your credentials from the Fynd Commerce portal:

  1. Log in to the Fynd Commerce.
  2. Navigate to CompanySettingsDevelopers section.
  3. Go to the Application Token and Clients tab to collect the credentials.
  4. Create a new client or use an existing one to obtain your company ID and credentials.

Project Setup

  1. Create a new directory for your project.
  2. Navigate to your project directory.
  3. Create a new JavaScript file (e.g., getProductDetails.js).

Install Dependencies

  1. Install the FDK Client JavaScript SDK:
npm install @gofynd/fdk-client-javascript
  1. Initialize your Node.js project.
npm init -y

SDK Configuration

The following code initializes the Fynd Platform SDK for headless architecture. This configuration establishes the foundation for all API interactions with Fynd's backend services.

import { PlatformConfig, PlatformClient } from "@gofynd/fdk-client-javascript";

const platformConfig = new PlatformConfig({
companyId: "0001", // Replace with your actual company ID
apiKey: "1234a5bcxxxxxxxxxxxxxxx", // Replace with your API key
apiSecret: "A1BbcdefGHIjKlM", // Replace with your API secret
domain: "https://api.fynd.com",
});

// Set logging level for debugging
platformConfig.setLogLevel("debug");

The PlatformConfig creates a configuration object containing your Fynd company credentials. The configuration includes the Company ID, API Key, API Secret, and the API domain endpoint, which is essential for authenticating requests to the Fynd platform.

Logging Configuration

The SDK provides comprehensive logging capabilities to help with development and debugging. Here, we have used debug.

platformConfig.setLogLevel("debug");

Available Log Levels

Choose the appropriate log level based on your environment and debugging needs.

  • trace: Most detailed logs, including all internal operations
  • debug: Detailed information useful for debugging (recommended for development)
  • info: General information about application operations
  • warn: Warnings about potential issues
  • error: Error messages only

Authentication

Authenticate your application using client credentials flow:

// Obtain access token using client credentials
const token = await platformConfig.oauthClient.getAccesstokenObj({
grant_type: "client_credentials",
});

// Set the token for subsequent API calls
platformConfig.oauthClient.setToken(token);

// Initialize the platform client
const platformClient = new PlatformClient(platformConfig);

This authentication flow:

  1. Requests an access token using the client credentials grant type.
  2. Sets the received token for future API requests.
  3. Creates a platform client instance for making API calls.

Fetch Product Details

Retrieve product information using the product slug:

const response = await platformClient
.application("1234567890a3b94c7396b7ab") // Replace with your application ID
.catalog.getProductDetailBySlug({
slug: "product_slug-12829384", // Replace with your product slug
});

console.log("Product Details:", response);

Parameters:

  • application(): Specifies the application ID (sales channel/storefront)
  • slug: Unique product identifier

Execute the Script

Run the following command to get the product details:

node getProductDetails.js

Expected Response

Upon successful execution, you'll receive a comprehensive product object similar to this:

{
type: 'product',
grouped_attributes: [
{ title: 'Product Details', details: [Array] }
],
medias: [
{
type: 'image',
url: '/products/pictures/item/free/original/liberty/FUNWAY-2_Yellow/0/DjHTI1SkRd-FUNWAY-2-YELLOW.jpg'
},
{
type: 'image',
url: '/products/pictures/item/free/original/liberty/FUNWAY-2_Yellow/1/2R0I-EF4ww-IMG_3375.jpg'
},
{
type: 'image',
url: '/products/pictures/item/free/original/liberty/FUNWAY-2_Yellow/2/3ssOd3bmSq-IMG_3376.jpg'
},
{
type: 'image',
url: '/products/pictures/item/free/original/liberty/FUNWAY-2_Yellow/3/XuzNczGpnh-IMG_3377.jpg'
}
],
brand: {
name: 'Generic',
uid: 5989,
logo: {
type: 'image',
url: 'https://cdn.fynd.com/v2/falling-surf-7c8bb8/fyprod/wrkr/brands/pictures/square-logo/original/AogxD7pYK-Logo.png'
},
action: { page: [Object], type: 'page' },
_custom_json: {}
},
uid: 12829384,
slug: 'product_slug-12829384',
attributes: {
'marketer-name': 'Abhishek Kumar',
essential: 'No',
season: 'Rain',
primary_material: 'Nylon',
'packaging-type': 'Packaged',
'primary-colour-hex-code': 'fbf30e',
'age-group': 'Adults',
occasion: 'Rainwear',
'marketer-address': 'PowerPartner',
gender: [ 'Men', 'Boys' ],
'net-quantity': '1 N',
lifestyle: 'Casualwear',
primary_color: 'Black',
boot_length: 'Ankle',
sustainable: 'Regular',
closure_type: 'Velcro',
product_details: '',
short_description: '',
brand_name: 'Generic',
primary_color_hex: '000000',
item_code: 'm3cy6ddw_PO',
country_of_origin: 'India',
brand: 'Generic'
},
name: 'All Weather Sandal',
has_variant: false,
categories: [
{
id: 176,
uid: '176',
name: 'Sandals',
slug: 'sandals',
logo: [Object],
action: [Object],
_custom_json: {}
}
],
tryouts: [],
promo_meta: {},
rating: null,
rating_count: null,
image_nature: 'standard',
tags: [],
teaser_tag: { tag: 'New' },
no_of_boxes: 1,
product_online_date: '2021-12-06T11:57:51.342000',
custom_order: {
manufacturing_time: 0,
is_custom_order: false,
manufacturing_time_unit: 'days'
},
highlights: [],
description: '',
short_description: '',
country_of_origin: 'India',
similars: [ 'category' ]
}

Was this section helpful?