> For the complete documentation index, see [llms.txt](https://help.openloyalty.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.openloyalty.io/technical-guide/api-fundamentals/best-practices.md).

# Best Practices

To ensure a robust, maintainable, and user-friendly API integration, adhere to the following best practices:

* **Error Handling and Response Codes**: Use appropriate HTTP status codes to indicate the outcome of API requests (e.g., 200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, 500 Internal Server Error). Integration layer should react and respond to all error messages and ensure a proper handling of different HTTP error codes from 4xx to 5xx.
* **Rate Limiting and Request Throttling:** Implement rate limiting to control the number of requests a client can make within a specified time window, preventing abuse or overloading of the API. Return the "429 Too Many Requests" status code when a client exceeds the limit.
* **Pagination and Filtering:** Use pagination to break large data sets into smaller, manageable chunks. Implement query parameters for filtering, sorting, and searching to help clients access relevant data efficiently. For example, use "\_itemsOnPage" and "\_page" parameters to control the number of records returned and the starting position within the data set.
* **Fetching Large Datasets:** To efficiently retrieve large datasets via the API, we recommend using the scrolling mechanism instead of traditional pagination with `_page` . This method is optimized for performance when fetching a high volume of records.
* **Caching and Performance Optimization:** Utilize caching strategies, such as ETag and Last-Modified headers, to minimize the need for repetitive API calls and reduce the load on the server. Apply performance optimizations, like data compression and minification, to decrease response payload sizes and improve client-side performance.
* **Retry Mechanisms and Idempotency:** Integrate retry mechanisms with exponential backoff for transient failures. This ensures that API requests are retried with increasing delays, minimizing the risk of overloading the system. Implement idempotent endpoints for non-idempotent HTTP methods like POST and PATCH, which allows clients to safely retry requests without causing unintended side effects.
* **`User-Agent` Header:** Always include a `User-Agent` header in your API requests. Requests without this header are blocked at the infrastructure level. Most HTTP clients set it automatically, but if yours doesn't, configure it explicitly — any descriptive value is acceptable (e.g. `MyApp/1.0`).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.openloyalty.io/technical-guide/api-fundamentals/best-practices.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
