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
-
Fynd Developer Kit (FDK) is installed
-
Node.js v20↗ or later
-
Before you begin, collect the following credentials and identifiers from the Fynd Commerce platform for headless implementation:
- Client ID
- Client Secret
- Company ID
These credentials establish the connection between your API calls and your Fynd Commerce account, ensuring secure and authenticated access to platform resources. Refer to Step to Collect Credentials
Obtaining Credentials
Follow these steps to retrieve your credentials from the Fynd Commerce portal:
- Log in to the Fynd Commerce.
- Navigate to Company →Developers section.
- Go to the Application Token and Clients tab to collect the credentials.
- Create a new client or use an existing one to obtain your company ID and credentials.
Project Setup
- Create a new directory for your project.
- Navigate to your project directory.
- Create a new JavaScript file (e.g.,
getProductDetails.js).
Install Dependencies
- Install the FDK Client JavaScript SDK:
npm install @gofynd/fdk-client-javascript
- 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: "a1b2c3xxxxxxxxx", // 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");