Flipkart Marketplace
ShoppingHow to Use the Flipkart Seller API with JavaScript
The Flipkart Seller API allows you to automate various tasks related to your Flipkart seller account, such as order management, product listing, and inventory management. In this tutorial, we will show you how to use the API with JavaScript, along with some example API code snippets.
Step 1: Get Your Flipkart Seller API Credentials
To use the Flipkart Seller API, you need to have a Flipkart seller account and request API access. Once you have access, you can log in to the Flipkart Seller Dashboard and navigate to the API section to generate your API credentials (flipkart_API_key and flipkart_API_token). Keep these credentials confidential, as they are used to authenticate requests to the API.
Step 2: Installing Required Packages
Next, we need to install the required packages to make API requests in JavaScript. We can use the request
package, which is a popular package to make HTTP requests in Node.js.
npm install request
Step 3: Making API Requests
We can use the request
package to make API requests to the Flipkart Seller API. The following code snippet shows how to make a GET request to get the list of orders.
const request = require('request');
const url = 'https://api.flipkart.com/sellers/v3/orders/list';
const options = {
url: url,
headers: {
Authorization: 'Bearer ' + flipkart_API_token,
'X-user-agent': 'Mozilla/5.0',
},
};
request.get(options, (err, res, body) => {
if (err) {
console.log('Error:', err);
} else {
console.log(res.statusCode, body);
}
});
The above code will make a GET request to the API endpoint https://api.flipkart.com/sellers/v3/orders/list
with the required headers. The response body will be logged to the console.
Similarly, we can make a POST request to create a new product listing. The following code snippet shows how to make a POST request to create a new product listing.
const request = require('request');
const url = 'https://api.flipkart.com/sellers/v3/products';
const data = {
'identifier': {
'supc': 'SUPC12345'
},
'metadata': {
'title': 'My Product',
'mrp': 1000,
'selling_price': 900,
'product_description': 'Product Description'
},
'listing': {
'visibility': 'default'
},
'fulfillment_profile_details': {
'fulfillment_profile_id': 'profile_id'
}
};
const options = {
url: url,
headers: {
Authorization: 'Bearer ' + flipkart_API_token,
'X-user-agent': 'Mozilla/5.0',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
};
request.post(options, (err, res, body) => {
if (err) {
console.log('Error:', err);
} else {
console.log(res.statusCode, body);
}
});
The above code will make a POST request to the API endpoint https://api.flipkart.com/sellers/v3/products
with the required headers and request body. The response body will be logged to the console.
Conclusion
The Flipkart Seller API is a powerful tool to automate various tasks related to your Flipkart seller account. In this tutorial, we showed you how to use the API with JavaScript, along with some example API code snippets. With this knowledge, you can build your own custom applications that integrate with the Flipkart Seller API.