API Parameters
API parameters tell the server what you want. There are three types: URL path parameters, query string parameters, and body parameters. Each is used in different situations.
Parameter Types
URL path parameters: embedded in the URL path
/orders/{order_id} → /orders/ORD-123
Used for identifying a specific resource
Query string parameters: appended after the URL as ?key=value
/orders?status=pending&limit=10
Used for filtering, sorting, and pagination
Body parameters: sent in the request body as JSON
{"customer_email": "user@example.com", "amount": 49.99}
Used for POST/PUT/PATCH operations — when creating or updating resources
Header parameters: sent in request headers
Authorization: Bearer TOKEN
Content-Type: application/json
Used for authentication and content negotiation
Parameter Examples
# Different parameter types in practice
import requests
BASE_URL = "https://api.example.com"
API_KEY = "your_api_key_here"
# 1. Path parameter — get order by ID
order_id = "ORD-456"
response = requests.get(
f"{BASE_URL}/orders/{order_id}", # path parameter in URL
headers={"Authorization": f"Bearer {API_KEY}"}
)
# 2. Query parameters — list orders with filters
response = requests.get(
f"{BASE_URL}/orders",
params={ # query string parameters
"customer_id": "C123",
"status": "shipped",
"limit": 20,
"page": 1
},
headers={"Authorization": f"Bearer {API_KEY}"}
)
# 3. Body parameters — create a new order
response = requests.post(
f"{BASE_URL}/orders",
json={ # body parameters as JSON
"customer_id": "C123",
"items": [{"sku": "PRD-001", "qty": 2}],
"shipping_address": "123 Main St, London"
},
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
)
print("Status codes:", 200, 200, 201) # Expected responses