The ApniDukaan platform provides both REST and GraphQL APIs for comprehensive e-commerce functionality. All APIs are accessible through the API Gateway at http://localhost:4000.
- API Gateway:
http://localhost:4000 - Frontend:
http://localhost:3000 - GraphQL Endpoint:
http://localhost:4000/graphql
All protected endpoints require a valid JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>POST /api/auth/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "securepassword",
"phone": "+1234567890"
}POST /api/auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "securepassword"
}POST /api/auth/forgot-password
Content-Type: application/json
{
"email": "john@example.com"
}POST /api/auth/reset-password
Content-Type: application/json
{
"token": "reset-token",
"password": "newpassword"
}GET /api/products?page=1&limit=10&category=electronics&sort=price&order=ascGET /api/products/:idGET /api/products/slug/:slugGET /api/products/featuredGET /api/products/:id/relatedPOST /api/products
Authorization: Bearer <admin-token>
Content-Type: application/json
{
"name": "iPhone 15 Pro",
"description": "Latest iPhone with advanced features",
"price": 999,
"category": "electronics",
"images": ["image1.jpg", "image2.jpg"],
"inventory": 100,
"specifications": {
"color": "Space Black",
"storage": "256GB"
}
}PUT /api/products/:id
Authorization: Bearer <admin-token>
Content-Type: application/json
{
"name": "iPhone 15 Pro Max",
"price": 1099
}DELETE /api/products/:id
Authorization: Bearer <admin-token>GET /api/cart
Authorization: Bearer <user-token>POST /api/cart/items
Authorization: Bearer <user-token>
Content-Type: application/json
{
"productId": "product-id",
"quantity": 2
}PUT /api/cart/items/:itemId
Authorization: Bearer <user-token>
Content-Type: application/json
{
"quantity": 3
}DELETE /api/cart/items/:itemId
Authorization: Bearer <user-token>DELETE /api/cart
Authorization: Bearer <user-token>POST /api/orders
Authorization: Bearer <user-token>
Content-Type: application/json
{
"items": [
{
"productId": "product-id",
"quantity": 2,
"price": 199.99
}
],
"shippingAddress": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zipCode": "10001",
"country": "USA"
},
"paymentMethod": "credit_card"
}GET /api/orders
Authorization: Bearer <user-token>GET /api/orders/:id
Authorization: Bearer <user-token>PUT /api/orders/:id/status
Authorization: Bearer <admin-token>
Content-Type: application/json
{
"status": "shipped",
"trackingNumber": "TRK123456789"
}POST /api/payments/create-intent
Authorization: Bearer <user-token>
Content-Type: application/json
{
"amount": 199.99,
"currency": "USD",
"orderId": "order-id"
}POST /api/payments/process
Authorization: Bearer <user-token>
Content-Type: application/json
{
"paymentIntentId": "pi_1234567890",
"orderId": "order-id"
}GET /api/payments/methods/:customerId
Authorization: Bearer <user-token>GET /api/search?q=iphone&category=electronics&minPrice=100&maxPrice=1000&sort=price&order=ascGET /api/search/popularGET /api/search/suggestions?q=iphPOST /api/notifications/welcome
Content-Type: application/json
{
"email": "user@example.com",
"name": "John Doe"
}POST /api/notifications/order-confirmation
Content-Type: application/json
{
"email": "user@example.com",
"orderId": "order-id",
"orderDetails": {
"total": 199.99,
"items": ["iPhone 15 Pro"]
}
}POST /api/notifications/sms
Content-Type: application/json
{
"phone": "+1234567890",
"message": "Your order has been shipped!",
"type": "shipping_update"
}type Query {
products(filter: ProductFilter, pagination: PaginationInput): ProductConnection
product(id: ID!): Product
productBySlug(slug: String!): Product
categories: [Category!]!
cart: Cart
orders(filter: OrderFilter): [Order!]!
order(id: ID!): Order
search(query: String!, filters: SearchFilters): SearchResult
}
type Mutation {
# Authentication
register(input: RegisterInput!): AuthPayload!
login(email: String!, password: String!): AuthPayload!
forgotPassword(email: String!): Boolean!
resetPassword(token: String!, password: String!): Boolean!
# Cart
addToCart(productId: ID!, quantity: Int!): Cart!
updateCartItem(itemId: ID!, quantity: Int!): Cart!
removeFromCart(itemId: ID!): Cart!
clearCart: Cart!
# Orders
createOrder(input: CreateOrderInput!): Order!
updateOrderStatus(id: ID!, status: OrderStatus!): Order!
# Products (Admin)
createProduct(input: CreateProductInput!): Product!
updateProduct(id: ID!, input: UpdateProductInput!): Product!
deleteProduct(id: ID!): Boolean!
}
type Subscription {
orderStatusUpdated(orderId: ID!): Order!
newProductAdded: Product!
}query GetProducts($filter: ProductFilter, $pagination: PaginationInput) {
products(filter: $filter, pagination: $pagination) {
edges {
node {
id
name
price
description
images
category {
id
name
}
inventory
averageRating
reviewCount
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
totalCount
}
}query GetCart {
cart {
id
items {
id
product {
id
name
price
images
}
quantity
totalPrice
}
totalItems
totalPrice
}
}mutation CreateOrder($input: CreateOrderInput!) {
createOrder(input: $input) {
id
status
total
items {
product {
name
price
}
quantity
}
shippingAddress {
street
city
state
zipCode
}
createdAt
}
}{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input data",
"details": [
{
"field": "email",
"message": "Email is required"
}
],
"timestamp": "2024-01-15T10:30:00Z",
"requestId": "req_123456789"
}
}| Code | Status | Description |
|---|---|---|
VALIDATION_ERROR |
400 | Invalid input data |
UNAUTHORIZED |
401 | Authentication required |
FORBIDDEN |
403 | Insufficient permissions |
NOT_FOUND |
404 | Resource not found |
CONFLICT |
409 | Resource already exists |
RATE_LIMITED |
429 | Too many requests |
INTERNAL_ERROR |
500 | Internal server error |
API endpoints are rate-limited to prevent abuse:
- Authentication endpoints: 5 requests per minute per IP
- General API endpoints: 100 requests per minute per user
- Search endpoints: 50 requests per minute per user
- Admin endpoints: 200 requests per minute per admin
Most list endpoints support pagination:
page: Page number (default: 1)limit: Items per page (default: 10, max: 100)sort: Sort fieldorder: Sort direction (ascordesc)
{
"data": [...],
"pagination": {
"page": 1,
"limit": 10,
"total": 100,
"totalPages": 10,
"hasNext": true,
"hasPrev": false
}
}The platform supports webhooks for real-time updates:
order.created: When a new order is createdorder.updated: When an order status changespayment.completed: When a payment is successfulproduct.updated: When a product is updated
{
"event": "order.created",
"timestamp": "2024-01-15T10:30:00Z",
"data": {
"orderId": "order_123456789",
"customerId": "customer_123456789",
"total": 199.99,
"status": "pending"
}
}npm install @apnidukaan/sdkimport { ApniDukaanClient } from '@apnidukaan/sdk';
const client = new ApniDukaanClient({
apiUrl: 'http://localhost:4000',
apiKey: 'your-api-key'
});
// Get products
const products = await client.products.list({
category: 'electronics',
limit: 10
});
// Create order
const order = await client.orders.create({
items: [{ productId: 'prod_123', quantity: 2 }],
shippingAddress: { /* address */ }
});Import the Postman collection: Download Collection
# Get products
curl -X GET "http://localhost:4000/api/products?limit=5" \
-H "Authorization: Bearer your-token"
# Create order
curl -X POST "http://localhost:4000/api/orders" \
-H "Authorization: Bearer your-token" \
-H "Content-Type: application/json" \
-d '{"items":[{"productId":"prod_123","quantity":2}]}'For API support and questions:
- Email: api-support@apnidukaan.com
- Documentation: API Docs
- Status Page: API Status
Last updated: January 2024