Best Practices for Building an API Integration

Best Practices for Building an API Integration

Introduction

When you are working with APIs, it is easy to forget how much impact your integration can have – not just on your own integration, but on the servers you are calling. Poorly-optimized API usage can slow things down and cause errors on both sides. Here are some straightforward tips to help you get the most out of any API without creating unnecessary problems.


Do not Make the Same Call Over and Over

One of the most common mistakes is sending the same request again and again, even when the data has not changed. It clogs up the network and slows down both your system and the API. If you pull the same list or object repeatedly, this is a sign that you could be caching it instead.

Try storing commonly-used data locally and only updating it when needed. For example, refreshing your cache once or twice a day is often enough for things like project lists or user info.


Only Ask for What You Need

APIs often give you tools for filtering results or limiting what comes back. Use them. If you only need a list of ‘active’ projects, do not ask for all of them and then sort it afterwards. You will save bandwidth, speed up responses and reduce the load on both ends.


Avoid Polling When You Can Use Callbacks

Polling (repeatedly asking the server “Have you finished yet?”) is often a last resort. The XTM API supports the use of many callbacks that can inform you about project status – use them. They let you know as soon as something is ready without needing to keep checking in.

If polling really is the only option for your integration, space out your checks – do not hammer the API every few seconds. Depending on the situation, checking every 10 to 15 minutes is usually more than enough.


Keep an Eye on Your Usage

Monitoring your API calls is a great way to spot problems early. Are you calling the same endpoint hundreds of times per hour? Are you getting a lot of failed responses? Set up some basic logging or analytics so you can catch these things before they turn into major issues.


Make It Easy to Maintain

Use clear structures and avoid hard-coding things like specific parameters within an API request. Keep your logic modular so you can update or replace parts without breaking everything else. The API might change over time, and even though we make sure that our calls are backward-compatible with old attributes, it would be best if your integration was flexible enough to handle those updates.


Try to Keep the Number of API Calls Manageable

It is best to keep your total API usage under control. As a general rule, try to stay below 100 calls per minute. Exceeding that rate might lead to throttling or blocked requests, especially during peak hours, if you are on a multi-tenant instance.

If your system is sending hundreds or thousands of calls in a short period, it is probably time to look into batching, caching, or rethinking how and when you are making requests.


Check Before You Act

Before performing any actions via the XTM API, it is essential to verify the current state of the project, step, or object you are working with. Acting too early, without confirming readiness, can lead to failed operations, ignored requests or unintended side effects.

Key examples:

  • After project creation or file upload:

    • Always check the analysisStatus before performing actions such as file upload, workflow assignment or step transitions. Acting before analysis completes can result in incomplete workflows or errors.

  • Activating from the archived or auto-archived state:

    • Before performing actions on a project, ensure the project’s activity has ACTIVE status. Attempting to perform actions on a project that is in the middle of activation can result in the project being corrupted or other unforeseen issues.

Use callbacks whenever possible

While manual checks are necessary, the preferred and more robust approach is to rely on callbacks. Our system provides extensive callback support, including, but not limited to:

  • callback after analysis is completed.

  • callback after project is activated from archived state.

  • callback when a workflow action is performed.

  • callback on project/job is finished, and many others.

Using callbacks ensures that you only trigger actions when the system is truly ready, reducing unnecessary polling, improving reliability and ensuring smoother automation.

Best practice:

Register relevant callbacks during integration and structure your workflows to react to those callbacks, instead of acting immediately after asynchronous operations are triggered.

If you have any doubts about XTM API usage, ask…

If you encounter any questions or issues when it comes to XTM API usage while creating an integration, feel free to ask XTM Support. We will be glad to help you and explain anything that is unclear. It is always better to ask than to build something inefficient or unstable.