Product API Documentation

Overview

The Product API provides access to detailed Product data.Product Api is REStfull Api. Users can retrieve details of one or more Products without an API key.the response will be in JSON. For inserting, updating, or deleting records, an API key is required. Only approved records are visible to all users, while each user can fetch their own inserted records at separate endpoints. to get API key Login to your accout or if you dont have account you can create here. this API is free.

Authentication

To perform any data modifications (insert, update, delete), an API key is required. However, you can fetch product details without an API key.
you need to include your API Key in bearer token under Authorization header and then hit the endpoint

Base URL

https://productapi.live

API Endpoints

Get Single Approved product Detail

GET /api/products/:id

Fetch details of a single approved product by ID.

the complete url for thumbnailImage is : baseURL+/uploads/images/1728725176301.jpg

                
 {
 "_id": "670a40b8222fb6bd7c71d62e",
 "productCategory": "smartphone",
 "name": "iPhone 16 Pro",
 "brand": "apple",
 "description": "6.3″, Super Retina XDR display, ProMotion technology Always-On display, Titanium with textured matte glass back, Apple Intelligence, 6 core GPU, 6 core CPU",
 "basePrice": 999,
 "inStock": true,
"stock": 48,
 "storageOptions": [
"128GB",
"256GB",
"512GB",
"1TB"
],
"colorOptions": [
"Desert Titanium",
"Natural Titanium",
"White Titanium",
"Black Titanium"
             ],
"isApproved": true,
 "createdOn": "2024-10-12T09:26:16.304Z",
 "thumbnailImage": "1728725176301.jpg",
 "createdBy": "670397b485f1e925f2537d42",
 "__v": 0
}



     

Get Multiple Approved Products

GET /api/products

Fetch a list of approved Product.

Query Parameters:-

pageNumber // optional, default value is 1 click here to test perPage // optional, default value is 10 click here to test sortBy // optional, default field for sorting is “createdOn” click here to test sortOrder // optional, default value is asc (for ascending order) , for descending order use value desc click here to test click here to test all query Parameters

View User's Products

GET /api/myProducts (API Key Required)

Retrieve a list of all Product inserted by the authenticated user, both approved and unapproved.

View User's Products

GET /api/myProducts/:id (API Key Required)

Retrieve a Product by id as inserted by the authenticated user, both approved and unapproved.

Insert New Product

POST /api/saveProduct (API Key Required)

Insert a new Product record.

first you need to include your API Key in bearer token under Authorization header and then..
To insert the product detail you need to supply following fields:
productCategory  //  String, required
name             // String, required // this filed accepts unique value
brand            // String, required 
description      // String, required 
basePrice        // Number, required 
inStock          // Boolean, required 
thumbnailImage   // file, required // MAX Limit: 200 kb image size // only JPG, JPEG or PNG type aceepted
colorOptions   // Array [String,String,String] // accepts array of  Strings, this is optional field
storageOptions   // Array [String,String,String] // accepts array of   Strings, this is optional field
stock            // Number, optional


Update product

POST /api/updateProduct/:id (API Key Required)

Update a product record if created by the authenticated user. you can update only those records which are inserted by you. just replace :id with actual _id of product


{
      
 "productCategory": "Smartphone"
"description": "The iPhone 12 Pro features a new design and edge-to-edge Super Retina XDR display",
 "basePrice": 1020,
"inStock": true,
"stock": 49,
"storageOptions": [
"128GB",
"256GB",
"512GB"
],
   
}

or if you want to change product image along with other fields then you need to include header "uploadImage" and its value "yes". upload image under file name "thumbnailImage"

Delete Product

DELETE /api/deleteProduct/:id (API Key Required)

Delete a product record if created by the authenticated user. you can delete product detail inserted by you

LIMIT

Authenticated user can insert 30 decuments and modify or delete the same

Admin Approval

Records inserted by a user are visible only to the creator until approved by an admin. Once approved, they become visible to all users. Only the creator can update or delete their records.

Error Handling

Status Code Description
200 OK
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
500 Internal Server Error