Skip to main content

Audience:

Developers

Generate an account statement using the API

Generate an account statement for a custom time period with the API.

Guide

  1. Call the generateAccountStatement mutation.
  2. Add the accountId (line 4).
  3. Add the openingDate and closingDate using format YYYY-MM-DDT00:00:00.000Z (lines 5-6).
    • Maximum period: three months.
  4. Set the language for your account statement, and choose the file format (PDF or CSV) (lines 7-8).
  5. Add all information you'd like to review about the statement (lines 11-27).

Mutation

Open in API Explorer
mutation GenerateAccountStatement {
generateAccountStatement(
input: {
accountId: "$ACCOUNT_ID"
openingDate: "2024-04-12T00:00:00.000Z"
closingDate: "2024-06-12T00:00:00.000Z"
language: nl
format: PDF
}
) {
closingDate
createdAt
feeCredits {
currency
value
}
feeDebits {
currency
value
}
id
openingDate
period
statusInfo {
status
}
updatedAt
}
}

Payload

The mutation returns all of the requested information.

The period field shows Custom (line 16) for on-demand statements; statements Swan generates automatically each month show Monthly.

The statusInfo.status shows Pending while Swan generates the statement (line 18).

{
"data": {
"generateAccountStatement": {
"closingDate": "2024-06-12T00:00:00.000Z",
"createdAt": "2024-06-20T15:56:50.096Z",
"feeCredits": {
"currency": "EUR",
"value": "5.50"
},
"feeDebits": {
"currency": "EUR",
"value": "12.00"
},
"id": "$ACCOUNT_STATEMENT_ID",
"openingDate": "2024-04-12T00:00:00.000Z",
"period": "Custom",
"statusInfo": {
"status": "Pending"
},
"updatedAt": "2024-06-20T15:56:52.423Z"
}
}
}

Retrieve generated statement

After generating the account statement, the statusInfo > status changes to Generated. When the status is Generated, you can retrieve the download URL.

  1. Call the accountStatement query.
  2. Add the account statement id (line 2).
  3. Add statusInfo for all statuses (line 8). Find the URL to download the statement in statusInfo > GeneratedStatusInfo > url (line 12).
Open in API Explorer
query GetAccountStatement {
accountStatement(id: "$ACCOUNT_STATEMENT_ID") {
closingDate
createdAt
id
openingDate
period
statusInfo {
status
... on GeneratedStatusInfo {
status
url
}
... on PendingStatusInfo {
status
}
... on FailedStatusInfo {
status
}
... on VoidedStatusInfo {
status
url
}
}
updatedAt
}
}

Payload

The period field shows Custom (line 8) for on-demand statements.

Use the url to download the statement (line 12).

  1. Copy the url from the payload.
  2. Paste the url into your preferred browser and press enter.
  3. The document downloads automatically.
{
"data": {
"accountStatement": {
"closingDate": "2024-06-12T00:00:00.000Z",
"createdAt": "2024-06-20T15:56:50.096Z",
"id": "$ACCOUNT_STATEMENT_ID",
"openingDate": "2024-04-12T00:00:00.000Z",
"period": "Custom",
"statusInfo": {
"__typename": "GeneratedStatusInfo",
"status": "Generated",
"url": "$DOWNLOAD_URL"
},
"updatedAt": "2024-06-20T15:56:58.234Z"
}
}
}
Account statement statuses
  • Pending: The statement is being generated.
  • Generated: The statement is ready to download. The url field contains the download link.
  • Failed: Statement generation failed. Double-check your account ID and generate a new statement.
  • Voided: The statement has been voided. A voided statement url is still available for reference.