Api ReferenceIdempotent Request

Idempotency: Preventing Double Actions

  • What it is: Idempotency is a way to ensure that you don’t accidentally perform the same action twice, even if you send the same request multiple times.
  • Why it’s needed: Sometimes, network issues can cause a request to fail or not get a response. Without idempotency, retrying the request could cause problems, like double charging a customer.
  • How it works: You use a unique key to tell Fiablepay, “This is the same request I sent earlier.”

The Idempotency Key

  • Unique Identifier: The key (Idempotency-Key) is a unique value generated by you for each request.
  • How to generate it: You need to create keys in a way that they are not repetitive (a unique ID or random value is useful).
  • Where to include: Pass the Idempotency-Key as a header with your request.

Fiablepay’s Idempotency Logic

  1. First Request: If it’s the first time Fiablepay sees a request with a specific Idempotency-Key, it processes the request. If the request is successful (2xx response), Fiablepay saves the response.
  2. Retry with Same Key: If you send the same request with the same Idempotency-Key again:
    • If previous request succeeded: Fiablepay returns the saved response without processing the request again.
    • If previous request failed: The request will be processed again.
  3. Errors: If the original API request generates an error, then response is not saved and request will be processed again
  4. GET Requests: Passing idempotent key with GET request will not have any impact

Key Points

  • POST Requests: Only use idempotency keys with POST requests (not GET requests).
  • Maximum Length: The Idempotency-Key value can be a maximum of 255 characters.
  • 24-Hour Validity: Any Idempotency-Key is only valid for 24 hours after Fiablepay processes the request (and saves the response). After 24 hours, the key is treated as a new key.

Example

Header:
"Idempotency-Key":"unique_value_123"

Think of it this way:

Imagine you’re ordering a pizza online. If you send your order and don’t get confirmation, you might click the submit button again. With idempotency, the restaurant knows it’s the same order, and it won’t make the pizza twice.

In Short: Idempotency makes sure that you don’t accidentally duplicate transactions by using the Idempotency-Key header, keeping things accurate and safe.