Skip to main content

Fetch Company Categories

This use case shows how a headless integration can retrieve a company's product categories from Fynd using cURL. Categories help you build navigation, filters, and hierarchical menus in your custom storefronts and services.

Prerequisites

  • Valid Fynd credentials: company_id, apiKey, and apiSecret.
  • A token generated via the client_credentials flow.

Endpoint

Implementation Steps

1. Set Up Configuration

Set up your Fynd API configuration using the credentials.

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

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

Refer to Fynd Commerce documentation.

2. Obtain Access Token

async function fetchCompanyCategory() {
try {
// Obtain access token
const tokenObj = await platformConfig.oauthClient.getAccesstokenObj({
grant_type: "client_credentials",
});
}}
const token = tokenObj.access_token;

3. cURL Request

Replace placeholders with your values.

curl -X GET \
"https://api.fynd.com/service/platform/catalog/v1.0/company/1234/category/" \
-H "Authorization: Bearer Abc1NGI1Y1I1MzMyODAwNjg1AjU1AjAkOkszAnh1cGRyWEdOaBCDE==" \
  • {company_id}: Your company ID on Fynd
  • {authorization_token}: OAuth access token obtained using client credentials

Final Output

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

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

// Async function to obtain token and fetch company inventories
async function fetchCompanyCategory() {
try {
// Obtain access token
const tokenObj = await platformConfig.oauthClient.getAccesstokenObj({
grant_type: "client_credentials",
});

const token = tokenObj.access_token;

const response = await fetch(`https://api.fynd.com/service/platform/catalog/v1.0/company/${platformConfig.companyId}/category/`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`,
},
});

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const inventoryData = await response.json();
console.log(inventoryData);

return inventoryData;
} catch (error) {
console.error('Error fetching company inventories:', error);
}
}

// Example usage:
fetchCompanyCategory();

Response

The actual schema may include more fields and nested structures. Below is a representative example to help you get started.

{
"items": [
{
"uid": 101,
"name": "Men",
"slug": "men",
"level": 1,
"is_active": true,
"children": [
{
"uid": 201,
"name": "Clothing",
"slug": "men-clothing",
"level": 2,
"is_active": true
}
]
},
{
"uid": 102,
"name": "Women",
"slug": "women",
"level": 1,
"is_active": true,
"children": []
}
],
"page": {
"current": 1,
"size": 20,
"has_next": false,
"item_total": 2
}
}

Was this section helpful?