Audience:
Developers
Generate an account statement using the API
Generate an account statement for a custom time period with the API.
Guide
- Call the
generateAccountStatementmutation. - Add the
accountId(line 4). - Add the
openingDateandclosingDateusing formatYYYY-MM-DDT00:00:00.000Z(lines 5-6).- Maximum period: three months.
- Set the
languagefor your account statement, and choose the fileformat(PDForCSV) (lines 7-8). - Add all information you'd like to review about the statement (lines 11-27).
Mutation
Open in API Explorermutation 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.
- Call the
accountStatementquery. - Add the account statement
id(line 2). - Add
statusInfofor all statuses (line 8). Find the URL to download the statement instatusInfo>GeneratedStatusInfo>url(line 12).
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).
- Copy the
urlfrom the payload. - Paste the
urlinto your preferred browser and press enter. - 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. Theurlfield 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 statementurlis still available for reference.
Also available
Generate an account statementFrom the Dashboard