API Documentation

Your comprehensive guide to interacting with our services.

Introduction

Welcome to the official API documentation. This guide will help you integrate with our platform seamlessly. Our API is designed to be RESTful, using standard HTTP methods and returning JSON responses.

Base URL: https://api.example.com/v1

Authentication

All requests to the API must be authenticated. We use API keys for authentication. Your API key should be included in the Authorization header of your requests.

GET /auth/keys

Request a new API key.

Request Headers

Name Type Description
Authorization String Your current API key (e.g., Bearer YOUR_API_KEY).

Responses

Status Content Type Schema
200 OK application/json
{
    "api_key": "new_generated_key",
    "expires_at": "2024-12-31T23:59:59Z"
}
401 Unauthorized application/json
{
    "error": "Invalid or expired API key"
}

Endpoints

GET /users

Retrieves a list of all users. Supports pagination.

Query Parameters

Name Type Required Description
page Integer No The page number to retrieve. Defaults to 1.
limit Integer No The number of users per page. Defaults to 20. Max 100.

Request Headers

Name Type Description
Authorization String Required. Your API key (e.g., Bearer YOUR_API_KEY).

Responses

Status Content Type Schema
200 OK application/json
{
    "data": [
        {
            "id": "user-123",
            "username": "johndoe",
            "email": "john.doe@example.com",
            "created_at": "2023-10-27T10:00:00Z"
        },
        {
            "id": "user-456",
            "username": "janedoe",
            "email": "jane.doe@example.com",
            "created_at": "2023-10-27T10:05:00Z"
        }
    ],
    "pagination": {
        "current_page": 1,
        "total_pages": 5,
        "total_items": 100,
        "next_page": "/api/v1/users?page=2&limit=20",
        "prev_page": null
    }
}
401 Unauthorized application/json
{
    "error": "Invalid or expired API key"
}
GET /users/{id}

Retrieves details for a specific user by their ID.

Path Parameters

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

Request Headers

Name Type Description
Authorization String Required. Your API key (e.g., Bearer YOUR_API_KEY).

Responses

Status Content Type Schema
200 OK application/json
{
    "id": "user-123",
    "username": "johndoe",
    "email": "john.doe@example.com",
    "created_at": "2023-10-27T10:00:00Z",
    "updated_at": "2023-10-27T11:30:00Z"
}
401 Unauthorized application/json
{
    "error": "Invalid or expired API key"
}
404 Not Found application/json
{
    "error": "User not found"
}
POST /users

Creates a new user.

Request Body

Content Type Schema
application/json
{
    "username": "newuser",
    "email": "new.user@example.com",
    "password": "secure_password_123"
}

Request Headers

Name Type Description
Authorization String Required. Your API key (e.g., Bearer YOUR_API_KEY).
Content-Type String Required. Set to application/json.

Responses

Status Content Type Schema
201 Created application/json
{
    "id": "user-789",
    "username": "newuser",
    "email": "new.user@example.com",
    "created_at": "2023-10-27T12:00:00Z"
}
400 Bad Request application/json
{
    "error": "Invalid input",
    "details": [
        "Username is required.",
        "Email format is invalid."
    ]
}
401 Unauthorized application/json
{
    "error": "Invalid or expired API key"
}
409 Conflict application/json
{
    "error": "User with this email already exists"
}
PUT /users/{id}

Updates an existing user's information.

Path Parameters

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

Request Body

Content Type Schema
application/json
{
    "username": "updated_username",
    "email": "updated.email@example.com"
}

Request Headers

Name Type Description
Authorization String Required. Your API key (e.g., Bearer YOUR_API_KEY).
Content-Type String Required. Set to application/json.

Responses

Status Content Type Schema
200 OK application/json
{
    "id": "user-123",
    "username": "updated_username",
    "email": "updated.email@example.com",
    "created_at": "2023-10-27T10:00:00Z",
    "updated_at": "2023-10-27T13:00:00Z"
}
400 Bad Request application/json
{
    "error": "Invalid input",
    "details": [
        "Email format is invalid."
    ]
}
401 Unauthorized application/json
{
    "error": "Invalid or expired API key"
}
404 Not Found application/json
{
    "error": "User not found"
}
DELETE /users/{id}

Deletes a user by their ID.

Path Parameters

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

Request Headers

Name Type Description
Authorization String Required. Your API key (e.g., Bearer YOUR_API_KEY).

Responses

Status Content Type Schema
204 No Content No response body.
401 Unauthorized application/json
{
    "error": "Invalid or expired API key"
}
404 Not Found application/json
{
    "error": "User not found"
}

Error Handling

The API uses standard HTTP status codes to indicate the success or failure of a request. Error responses will include a JSON object with an error message and optionally a details field for more specific information.

Common error codes include:

  • 400 Bad Request: The request was malformed or contained invalid parameters.
  • 401 Unauthorized: Authentication failed or the API key is missing/invalid.
  • 403 Forbidden: The authenticated user does not have permission to perform the action.
  • 404 Not Found: The requested resource could not be found.
  • 405 Method Not Allowed: The HTTP method used is not supported for the requested resource.
  • 409 Conflict: The request could not be completed due to a conflict with the current state of the resource (e.g., creating a user with a duplicate email).
  • 429 Too Many Requests: The rate limit has been exceeded.
  • 500 Internal Server Error: An unexpected error occurred on the server.

Example Error Response:

{
    "error": "Resource not found",
    "details": "The requested item with ID 'item-abc' could not be located."
}

Rate Limiting

To ensure fair usage and stability, the API enforces rate limits. You can make a maximum of 1000 requests per minute per API key.

If you exceed the rate limit, you will receive a 429 Too Many Requests response. The response headers will also contain information about your current rate limit status:

  • X-RateLimit-Limit: The total number of requests allowed in the current window.
  • X-RateLimit-Remaining: The number of requests remaining in the current window.
  • X-RateLimit-Reset: The time in UTC seconds when the current window resets.