FDK client for Javascript
Get started with the Javascript Development SDK for Fynd Platform
npm install fdk-client-javascript --save
Using this method, you can require
fdk-client-javascript like so:
const {
ApplicationConfig,
ApplicationClient,
} = require("fdk-client-javascript");
For logging support user can pass logLevel
in ApplicationConfig
or PlatformConfig
while declaration.
Available logging levels: TRACE, DEBUG, INFO, WARN, ERROR.
Default log level: ERROR
const config = new ApplicationConfig({
applicationID: "YOUR_APPLICATION_ID",
applicationToken: "YOUR_APPLICATION_TOKEN",
locationDetails: "LOCATION_DETAILS_OBJECT"
});
const applicationClient = new ApplicationClient(config);
applicationClient.setLocationDetails({
pincode:"385001",
country: "India",
city: "Ahmedabad",
location: {longitude: "72.585022", latitude: "23.033863"}
});
async function getProductDetails() {
try {
const product = await applicationClient.catalog.getProductDetailBySlug({
slug: "product-slug"
});
console.log(product.name);
} catch (err) {
console.log(err);
}
}
getProductDetails();
const { PlatformConfig, PlatformClient } = require("fdk-client-javascript");
let platformConfig = new PlatformConfig({
companyId: "COMPANY_ID",
apiKey: "API_KEY",
apiSecret: "API_SECRET",
domain: "DOMAIN",
useAutoRenewTimer: true // Setting `true` will use timer based logic to refresh the access token. With `false` will issue refresh token just before any api call when it is expired.
});
async function getData() {
try {
// TODO: get token using OAuth
platformConfig.oauthClient.setToken(token.access_token);
const client = new PlatformClient(platformConfig);
// API's without application_id
const tickets = await client.lead.getTickets();
console.log("tickets", tickets);
// API's with application_id
const customers = await client
.application("APPLICATION_ID")
.user.getCustomers();
console.log("customers", customers);
} catch (err) {
console.log(err);
}
}
getData();
fdk-client-javascript includes Typescript definitions.
import { ApplicationConfig, ApplicationClient } from "fdk-client-javascript";