Inventory Management API

Overview

The Inventory Management API allows developers to manage product inventory, including adding, updating, retrieving, and deleting product information.

Base URL

https://api.inventory.com/v1

Authentication

This API uses API keys for authentication.

Endpoints

GET /products

Description: Retrieves a list of products.

Request Headers:

Authorization: Bearer <your_api_key>

Request Parameters:

  • category (optional): The category of products to return.

Response:

  • Success (200 OK):

    {
      "products": [
        {
          "id": 101,
          "name": "Product 1",
          "category": "Category A"
        },
        {
          "id": 102,
          "name": "Product 2",
          "category": "Category B"
        }
      ]
    }

POST /products

Description: Adds a new product to the inventory.

Request Headers:

Content-Type: application/json
Authorization: Bearer <your_api_key>

Request Body:

{
  "name": "New Product",
  "category": "Category A"
}

Response:

  • Success (201 Created):

    {
      "id": 103,
      "name": "New Product",
      "category": "Category A"
    }
  • Error (400 Bad Request):

    {
      "error": "Invalid product data"
    }

PUT /products/{id}

Description: Updates an existing product.

Request Headers:

Content-Type: application/json
Authorization: Bearer <your_api_key>

Request Parameters:

  • id (path parameter): The ID of the product to update.

Request Body:

{
  "name": "Updated Product",
  "category": "Category A"
}

Response:

  • Success (200 OK):

    {
      "id": 101,
      "name": "Updated Product",
      "category": "Category A"
    }
  • Error (404 Not Found):

    {
      "error": "Product not found"
    }

DELETE /products/{id}

Description: Deletes a product.

Request Headers:

Authorization: Bearer <your_api_key>

Request Parameters:

  • id (path parameter): The ID of the product to delete.

Response:

  • Success (200 OK):

    {
      "message": "Product deleted successfully."
    }
  • Error (404 Not Found):

    {
      "error": "Product not found"
    }

Example Code Snippets

Adding a New Product (Python)

import requests

url = "https://api.inventory.com/v1/products"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <your_api_key>"
}
data = {
    "name": "New Product",
    "category": "Category A"
}

response = requests.post(url, json=data, headers=headers)
print(response.json())

Retrieving Products (JavaScript)

const fetch = require('node-fetch');

const url = 'https://api.inventory.com/v1/products';
const options = {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer <your_api_key>'
  }
};

fetch(url, options)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));