API Reference

Introduction

Welcome to the API Reference for our platform. This document details all available API endpoints, their request and response formats, and usage guidelines. Use this API to programmatically interact with user, product, and order data.

All API requests should be made over HTTPS. The base URL for all API endpoints is: https://api.example.com/v1

Authentication

Authentication is performed by passing an API key in the Authorization header of your requests.

Required Headers

Authorization
Bearer YOUR_API_KEY

Replace YOUR_API_KEY with your actual API key. You can obtain an API key from your developer dashboard.

Users API

GET /users

Retrieves a list of all users.

Query Parameters

Name Type Required Description
limit Integer No Maximum number of users to return. Defaults to 20.
offset Integer No Number of users to skip before starting to collect the result set. Defaults to 0.
status String No Filter users by status (e.g., active, inactive).

Responses

Status Code Description Example
200 OK Successfully retrieved list of users.
application/json
[
    {
        "id": "usr_123abc",
        "name": "Alice Wonderland",
        "email": "alice@example.com",
        "status": "active",
        "created_at": "2023-10-27T10:00:00Z"
    },
    {
        "id": "usr_456def",
        "name": "Bob The Builder",
        "email": "bob@example.com",
        "status": "active",
        "created_at": "2023-10-27T10:05:00Z"
    }
]
401 Unauthorized Authentication failed.
application/json
{
    "error": "Unauthorized",
    "message": "Invalid API key."
}
POST /users

Creates a new user.

Request Body

application/json
{
    "name": "Charlie Chaplin",
    "email": "charlie@example.com",
    "status": "active"
}

Responses

Status Code Description Example
201 Created User successfully created.
application/json
{
    "id": "usr_789ghi",
    "name": "Charlie Chaplin",
    "email": "charlie@example.com",
    "status": "active",
    "created_at": "2023-10-27T11:00:00Z"
}
400 Bad Request Invalid input data.
application/json
{
    "error": "Bad Request",
    "message": "Email is already in use."
}
GET /users/{userId}

Retrieves a specific user by their ID.

Path Parameters

Name Type Required Description
userId String Yes The unique identifier of the user.

Responses

Status Code Description Example
200 OK Successfully retrieved user details.
application/json
{
    "id": "usr_123abc",
    "name": "Alice Wonderland",
    "email": "alice@example.com",
    "status": "active",
    "created_at": "2023-10-27T10:00:00Z",
    "updated_at": "2023-10-27T10:30:00Z"
}
404 Not Found User with the specified ID was not found.
application/json
{
    "error": "Not Found",
    "message": "User with ID 'usr_nonexistent' not found."
}
PUT /users/{userId}

Updates an existing user.

Path Parameters

Name Type Required Description
userId String Yes The unique identifier of the user to update.

Request Body

application/json
{
    "name": "Alice Smith",
    "status": "inactive"
}

Responses

Status Code Description Example
200 OK User successfully updated.
application/json
{
    "id": "usr_123abc",
    "name": "Alice Smith",
    "email": "alice@example.com",
    "status": "inactive",
    "created_at": "2023-10-27T10:00:00Z",
    "updated_at": "2023-10-27T11:30:00Z"
}
404 Not Found User not found.
application/json
{
    "error": "Not Found",
    "message": "User with ID 'usr_nonexistent' not found."
}
DELETE /users/{userId}

Deletes a user by their ID.

Path Parameters

Name Type Required Description
userId String Yes The unique identifier of the user to delete.

Responses

Status Code Description Example
204 No Content User successfully deleted. (No response body)
404 Not Found User not found.
application/json
{
    "error": "Not Found",
    "message": "User with ID 'usr_nonexistent' not found."
}

Products API

GET /products

Retrieves a list of all products.

Query Parameters

Name Type Required Description
category String No Filter products by category.
limit Integer No Maximum number of products to return. Defaults to 50.

Responses

Status Code Description Example
200 OK Successfully retrieved list of products.
application/json
[
    {
        "id": "prod_abc123",
        "name": "Wireless Mouse",
        "category": "Electronics",
        "price": 25.99,
        "in_stock": true
    },
    {
        "id": "prod_def456",
        "name": "Mechanical Keyboard",
        "category": "Electronics",
        "price": 79.50,
        "in_stock": false
    }
]
POST /products

Creates a new product.

Request Body

application/json
{
    "name": "Ergonomic Chair",
    "category": "Furniture",
    "price": 199.99,
    "in_stock": true,
    "description": "Comfortable ergonomic chair for long working hours."
}

Responses

Status Code Description Example
201 Created Product successfully created.
application/json
{
    "id": "prod_ghi789",
    "name": "Ergonomic Chair",
    "category": "Furniture",
    "price": 199.99,
    "in_stock": true,
    "description": "Comfortable ergonomic chair for long working hours.",
    "created_at": "2023-10-27T12:00:00Z"
}
GET /products/{productId}

Retrieves a specific product by its ID.

Path Parameters

Name Type Required Description
productId String Yes The unique identifier of the product.

Responses

Status Code Description Example
200 OK Successfully retrieved product details.
application/json
{
    "id": "prod_abc123",
    "name": "Wireless Mouse",
    "category": "Electronics",
    "price": 25.99,
    "in_stock": true,
    "description": "A high-precision wireless mouse with ergonomic design.",
    "created_at": "2023-10-26T09:00:00Z",
    "updated_at": "2023-10-27T09:15:00Z"
}
404 Not Found Product not found.
application/json
{
    "error": "Not Found",
    "message": "Product with ID 'prod_nonexistent' not found."
}
PUT /products/{productId}

Updates an existing product.

Path Parameters

Name Type Required Description
productId String Yes The unique identifier of the product to update.

Request Body

application/json
{
    "price": 27.50,
    "in_stock": false
}

Responses

Status Code Description Example
200 OK Product successfully updated.
application/json
{
    "id": "prod_abc123",
    "name": "Wireless Mouse",
    "category": "Electronics",
    "price": 27.50,
    "in_stock": false,
    "description": "A high-precision wireless mouse with ergonomic design.",
    "created_at": "2023-10-26T09:00:00Z",
    "updated_at": "2023-10-27T12:30:00Z"
}
404 Not Found Product not found.
application/json
{
    "error": "Not Found",
    "message": "Product with ID 'prod_nonexistent' not found."
}
DELETE /products/{productId}

Deletes a product by its ID.

Path Parameters

Name Type Required Description
productId String Yes The unique identifier of the product to delete.

Responses

Status Code Description Example
204 No Content Product successfully deleted. (No response body)
404 Not Found Product not found.
application/json
{
    "error": "Not Found",
    "message": "Product with ID 'prod_nonexistent' not found."
}

Orders API

GET /orders

Retrieves a list of all orders.

Query Parameters

Name Type Required Description
userId String No Filter orders by user ID.
status String No Filter orders by status (e.g., pending, shipped, delivered).
limit Integer No Maximum number of orders to return. Defaults to 50.

Responses

Status Code Description Example
200 OK Successfully retrieved list of orders.
application/json
[
    {
        "id": "ord_xyz789",
        "user_id": "usr_123abc",
        "total_amount": 105.49,
        "status": "shipped",
        "created_at": "2023-10-27T13:00:00Z"
    },
    {
        "id": "ord_uvw456",
        "user_id": "usr_456def",
        "total_amount": 50.00,
        "status": "pending",
        "created_at": "2023-10-27T13:05:00Z"
    }
]
POST /orders

Creates a new order.

Request Body

application/json
{
    "user_id": "usr_123abc",
    "items": [
        {
            "product_id": "prod_abc123",
            "quantity": 2
        },
        {
            "product_id": "prod_ghi789",
            "quantity": 1
        }
    ]
}

Responses

Status Code Description Example
201 Created Order successfully created.
application/json
{
    "id": "ord_rst123",
    "user_id": "usr_123abc",
    "total_amount": 130.98,
    "status": "pending",
    "created_at": "2023-10-27T14:00:00Z",
    "items": [
        {
            "product_id": "prod_abc123",
            "quantity": 2,
            "price_at_order": 27.50
        },
        {
            "product_id": "prod_ghi789",
            "quantity": 1,
            "price_at_order": 75.98
        }
    ]
}
400 Bad Request Invalid input data, e.g., product not found or insufficient stock.
application/json
{
    "error": "Bad Request",
    "message": "One or more items are invalid or out of stock."
}
GET /orders/{orderId}

Retrieves a specific order by its ID.

Path Parameters

Name Type Required Description
orderId String Yes The unique identifier of the order.

Responses

Status Code Description Example
200 OK Successfully retrieved order details.
application/json
{
    "id": "ord_xyz789",
    "user_id": "usr_123abc",
    "total_amount": 105.49,
    "status": "shipped",
    "shipping_address": {
        "street": "123 Main St",
        "city": "Anytown",
        "state": "CA",
        "zip_code": "90210"
    },
    "created_at": "2023-10-27T13:00:00Z",
    "updated_at": "2023-10-27T15:00:00Z",
    "items": [
        {
            "product_id": "prod_def456",
            "quantity": 1,
            "price_at_order": 79.50
        },
        {
            "product_id": "prod_abc123",
            "quantity": 1,
            "price_at_order": 25.99
        }
    ]
}
404 Not Found Order not found.
application/json
{
    "error": "Not Found",
    "message": "Order with ID 'ord_nonexistent' not found."
}