Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

Skip to main content

Idempotency

Idempotency ensures that API operations execute only once, even if you retry the same request multiple times. This prevents duplicate transactions caused by network issues, system interruptions, or request timeouts.

How it works

When you include an idempotencyKey in a supported mutation:

  1. First request: Swan generates a unique identifier, executes the operation, and stores the result with your key.
  2. Subsequent requests: Swan checks for existing operations and returns the current state instead of creating a new one.
  3. Key expiration: After 24 hours, the same key can be reused for a new operation.

Supported operations

Idempotency is available for operations that create resources or have side effects, including:

  • initiateCreditTransfers to prevent duplicate payments.
  • Additional mutations will support idempotency in future updates.

Idempotency key requirements

Your idempotencyKey must be:

  • A unique string: UUID v4 recommended (e.g., 156d000c-4b32-4e83-aa36-277f2c9b6290).
  • Maximum 255 characters.
  • Alphanumeric characters, hyphens, and underscores only.
  • Scoped to your authentication context: Keys are isolated by project and user, ensuring the same key used by different projects or users will not conflict.

Example usage

mutation ExampleWithIdempotency {
initiateCreditTransfers(
input: {
idempotencyKey: "156d000c-4b32-4e83-aa36-277f2c9b6290"
accountId: "$YOUR_ACCOUNT_ID"
consentRedirectUrl: "$YOUR_REDIRECT_URL"
creditTransfers: {
amount: { value: "100", currency: "EUR" }
sepaBeneficiary: {
iban: "IT23P0300203280632123553748"
name: "Francesca Verrilli"
isMyOwnIban: false
save: false
}
}
}
) {
... on InitiateCreditTransfersSuccessPayload {
payment {
id
statusInfo {
... on PaymentConsentPending {
consent {
consentUrl
}
}
}
}
}
}
}

Response behavior

First request

Returns the operation result and stores it with your idempotency key.

{
"data": {
"initiateCreditTransfers": {
"payment": {
"id": "cto_6b0b973e9c71de540776e300494be5fa",
"statusInfo": {
"__typename": "PaymentConsentPending",
"consent": {
"consentUrl": "https://identity.swan.io/consent?consentId=949872ab...",
"id": "949872ab-0c11-46b0-89d0-bc16c02db220"
}
}
}
}
}
}

Subsequent requests

Returns the current state of the original operation. If the payment status has changed (e.g., user provided consent), the response reflects this.

{
"data": {
"initiateCreditTransfers": {
"payment": {
"id": "cto_6b0b973e9c71de540776e300494be5fa",
"statusInfo": {
"__typename": "PaymentInitiated",
"status": "Initiated"
}
}
}
}
}

Error handling

Swan handles idempotency differently based on when errors occur.

Validation errors (before execution)

Requests that fail parameter validation (e.g., invalid IBAN format) never reach execution, so no idempotent result is stored. You can safely retry these requests with the same key after fixing the validation issues.

Business logic errors (during execution)

Requests that pass validation but fail during execution (e.g., insufficient funds) store the error result with the idempotency key. Subsequent requests with the same key return the identical error, even if conditions have changed.

For example, if a payment fails due to insufficient funds, retrying with the same idempotency key returns the same error even after the account is funded.

Best practices

  • Generate unique keys: Use UUID v4 or similar for each distinct operation.
  • Store keys locally: Keep track of idempotency keys for operations you might need to retry.
  • Handle current state: Your application should handle responses that reflect the current state, not just the initial state.
  • Use for critical operations: Always include idempotency keys for payment initiation and other critical operations.

Key expiration

Idempotency keys expire after 24 hours. After expiration:

  • The same key can be reused for a new operation.
  • Previous results are no longer accessible when using that key.
  • This prevents indefinite storage of operation results.