Request ID and Correlation ID are powerful header tools for debugging and tracing API requests in Straddle. This guide will explain what they are, how to use them, and best practices for implementation.

What are Request ID and Correlation ID?

Request ID

A Request ID is a user-defined identifier in the header of each API request. It helps in tracking and debugging individual API calls.

Correlation ID

A Correlation ID is a user-defined identifier in the header of each API request. It helps in tracing a sequence of operations across multiple systems or services.

How to Use Request ID and Correlation ID

You can include Request ID and Correlation ID in your API requests to Straddle by adding specific headers to your HTTP requests.

Using Request ID and Correlation ID

Here’s an example of creating a charge using the correct fields as specified in the OpenAPI schema, along with Request ID and Correlation ID:

Here’s an example of creating a customer:

Retrieving Request ID and Correlation ID

Straddle includes the Request ID and Correlation ID (if provided) in the response headers of every API request.

  • Request ID: Request-Id
  • Correlation ID: Correlation-Id

You can retrieve these headers from the API response to log them or use them for debugging purposes.

Best Practices

  1. Generate Unique IDs: Ensure that your Request IDs and Correlation IDs are unique. UUIDs are a good choice for this.

  2. Consistent Usage: Use Request IDs for every API call, and use Correlation IDs for all requests related to a single operation or transaction.

  3. Logging: Log both Request IDs and Correlation IDs in your application logs. This will make it easier to trace requests across your systems and Straddle.

  4. Error Handling: Include the Request ID and Correlation ID when logging errors or exceptions. This will help in debugging issues more effectively.

  5. Support Communication: When contacting Straddle support about a specific API request, always include the Request ID and Correlation ID (if applicable).

Implementation Example

Here’s an example of how you might implement Request ID and Correlation ID in a real-world scenario:

In this example, we generate a unique Correlation ID for the entire order processing operation, and unique Request IDs for each API call. This allows us to trace the entire order process across multiple API calls.

Conclusion

Using Request ID and Correlation ID effectively can significantly improve your ability to debug and trace API requests when integrating with Straddle. By implementing these best practices, you’ll be better equipped to monitor your integration, troubleshoot issues, and communicate effectively with Straddle support when needed.

For more information on how Request ID and Correlation ID behave with specific API endpoints, refer to our API Reference documentation.