Check it out! Get more templates! 👉
Last Update:16/09/2024
Metta's Creations | Notion Template Creator
This documentation provides a comprehensive guide to understanding and using the [Your API] REST API.
<aside> ❗ To interact with the API, you need an API key. You can obtain your API key from the API settings page. If this is your first time using the API, we recommend starting with the Getting Started Guide to learn how to generate an API key and set up your environment.
</aside>
The base URL for all API requests is https://api.example.com
. HTTPS is required for all API interactions.
The API follows RESTful conventions with operations performed using GET
, POST
, PUT
,PATCH
, and DELETE
requests on various resources. All request and response bodies are encoded as JSON.
"object"
Property): Each top-level resource in a JSON response has an "object"
property, which indicates the type of the resource. This is useful for determining the nature of the resource being returned. Examples include:
"database"
: Represents a database resource."page"
: Represents a page resource."user"
: Represents a user resource."block"
: Represents a block resource."id"
Property): Resources are uniquely identified by a UUIDv4 "id"
property. This ID can be used to reference the resource in subsequent API requests. Note that when making requests, you may omit dashes from the ID if copying it directly from a Notion URL. For example:
"123e4567-e89b-12d3-a456-426614174000"
"123e4567e89b12d3a456426614174000"
snake_case
): Property names within the JSON responses are formatted using snake_case
. This convention is consistent across different types of resources. For example:
"created_time"
: Represents the creation time of a resource."last_edited_by"
: Represents the user who last edited the resource."page_id"
: Represents the ID of a page.YYYY-MM-DDTHH:MM:SS.sssZ
. Example: "2024-09-16T14:45:30.000Z"
YYYY-MM-DD
. Example: "2024-09-16"
""
) to represent a lack of value, you should use null
to explicitly indicate that the value is unset. This applies to properties like URLs or rich text fields:
"url": ""
"url": null
These conventions help ensure that the data exchanged with the API is both consistent and easily interpreted.
Request samples are provided for each endpoint using common tools like cURL
and code snippets in popular SDKs. You can also use any HTTP client library of your choice.
Sample using cURL:
bash
Copy code
curl -X GET "<https://api.example.com/users>" \\
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Sample using JavaScript SDK:
javascript
Copy code
const exampleSDK = require('example-sdk');
exampleSDK.users.getAllUsers()
.then(response => console.log(response))
.catch(error => console.error(error));
SDKs: Check our SDK repository for various language-specific implementations.
Endpoints that return lists of objects support cursor-based pagination. By default, ten items are returned per request. Use the next_cursor
value from the response to fetch the next page of results.
Example Pagination Response:
{
"has_more": true,
"next_cursor": "eyJzIjoiaW5kZXgiLCJwIjoidXNlcnMifQ",
"object": "list",
"results": [ /* array of objects */ ]
}
HTTP Method | Endpoint | Description |
---|---|---|
GET | /users |
Retrieve all users. |
GET | /users/{user_id} |
Retrieve a specific user. |
POST | /posts |
Create a new post. |
PUT | /posts/{post_id} |
Update an existing post. |
DELETE | /posts/{post_id} |
Delete a specific post. |
GET | /posts/{post_id}/comments |
Retrieve comments for a post. |
POST | /posts/{post_id}/comments |
Add a new comment to a post. |
Field | Type | Description | Example Value |
---|---|---|---|
has_more |
boolean |
Indicates whether there are additional items available for retrieval beyond the current page of results. This field helps determine if further requests are necessary to fetch the complete set of items. | true (if more items exist) / false (if no more items) |
next_cursor |
string |
A cursor token used to retrieve the next page of results. This field is provided only when has_more is true. It allows the client to request subsequent pages of results by including this token in the start_cursor parameter of the next request. | "abc123xyz” |
object |
"list" |
Specifies the type of the object returned in the response. For paginated responses, this value is always "list", indicating that the response contains a list of items. This helps in understanding the structure of the response. | "list" |
results |
array of objects |
An array of items returned by the endpoint. Each object in the array represents an individual item in the response. The exact properties and structure of these objects depend on the specific endpoint and resource type. | [ { "id": "123", "name": "Item 1", "description": "Description of item 1" }, { "id": "124", "name": "Item 2", "description": "Description of item 2" } ] |
To ensure fair usage and maintain performance, the API enforces rate and size limits on requests.
The API imposes rate limits to prevent abuse and ensure equitable access.
429 Rate Limit Exceeded
error. This indicates that you have sent too many requests in a given time frame.<aside> ❗ Rate Limits May Change
The rate limits may be adjusted based on system demand and performance metrics. Different tiers of service might have distinct rate limits.
</aside>
The API enforces limits on the size of request parameters and depths.
Property | Size Limit | Description |
---|---|---|
Request Body Size | 10 MB | Maximum size of the request body. Exceeding this limit will result in a 400 Validation Error . |
Rich Text Length | 2000 characters | Maximum allowable length for rich text fields. |
File Size | 50 MB | Maximum allowable size for file uploads. |
Nested Request Depth | 5 levels | Maximum depth for nested requests. |
Requests that exceed these limits will trigger a 400 Validation Error
, indicating that the request cannot be processed due to size constraints.
HTTP status codes provide critical information regarding the outcome of your API request. Understanding these codes helps in diagnosing issues and handling errors effectively.
HTTP Status | Description | Detail |
---|---|---|
200 OK |
Successfully processed request. | The server successfully processed the request, and the response contains the requested data or confirmation of the action performed. |
Error responses contain more detail about the error in the response body, in the "code"
and "message"
properties.
HTTP Status | Code | Message | Description |
---|---|---|---|
400 Bad Request |
invalid_request |
The request format is incorrect. | The request format or syntax is invalid, which prevents the server from understanding and processing it. Verify and correct the request structure. |
401 Unauthorized |
unauthorized |
Authentication failed or token expired. | The authentication credentials provided are either invalid or have expired. Ensure that the token is correct and still valid. |
404 Not Found |
not_found |
Resource not found. | The requested resource does not exist on the server. Confirm that the URL is correct and that the resource is available. |
429 Too Many Requests |
rate_limited |
Rate limit exceeded. | The number of requests made in a given period exceeds the allowed rate limit. Wait before making further requests or optimize your request frequency. |
API versioning ensures that you can maintain compatibility with the API as it evolves. Each version of the API is identified by its release date, allowing for clear tracking and management of changes over time.
YYYY-MM-DD
2024-09-16
.To ensure that your requests use a specific version of the API, include the API-Version
header in your request. This practice helps avoid unexpected changes and ensures consistent behavior from the API.
Example Request:
Authorization
header for authenticated requests.API-Version
header to ensure compatibility with your application.By following these guidelines, you can manage API updates and maintain stability in your integration.
User objects represent users within the API. These objects are used in various API responses to provide details about the user involved in different actions.
Post objects represent individual posts within the API. They provide detailed information about specific posts.