Skip to content
124 changes: 107 additions & 17 deletions docs/topics/accounts/overview/guide-generate-statement.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,164 @@
title: Generate account statement
---

# Generate account statement
# Generate an account statement

Generate an account statement for a custom time period **using the API** or on your **Dashboard**.

## API guide {#guide}

1. Call the `generateAccountStatement` mutation.
1. Add the `accountId`.
1. Add the `openingDate` and `closingDate` with the following format: `YYYY-MM-DDT00:00:00.000Z` (up to three months).
1. Set the `language` for your account statement, and choose `PDF` or `CSV` if you'd like.
1. Add all information you'd like to review about the statement (lines 11-21).
1. Add the `openingDate` and `closingDate` using format `YYYY-MM-DDT00:00:00.000Z`.
- Maximum period: three months.
1. Set the `language` for your account statement, and provide the file `format` (`PDF` or `CSV`).
1. Add all information you'd like to review about the statement (lines 11-27).

### Mutation {#mutation}

<a href="https://explorer.swan.io?query=bXV0YXRpb24gR2VuZXJhdGVBY2NvdW50U3RhdGVtZW50IHsKICBnZW5lcmF0ZUFjY291bnRTdGF0ZW1lbnQoCiAgICBpbnB1dDogewogICAgICBhY2NvdW50SWQ6ICIkQUNDT1VOVF9JRCIKICAgICAgb3BlbmluZ0RhdGU6ICIyMDI0LTA0LTEyVDAwOjAwOjAwLjAwMFoiCiAgICAgIGNsb3NpbmdEYXRlOiAiMjAyNC0wNi0xMlQwMDowMDowMC4wMDBaIgogICAgICBsYW5ndWFnZTogbmwKICAgICAgc3RhdGVtZW50VHlwZTogUERGCiAgICB9CiAgKSB7CiAgICBjbG9zaW5nRGF0ZQogICAgY3JlYXRlZEF0CiAgICBmZWVzIHsKICAgICAgY3VycmVuY3kKICAgICAgdmFsdWUKICAgIH0KICAgIGlkCiAgICBvcGVuaW5nRGF0ZQogICAgcGVyaW9kCiAgICBzdGF0dXMKICAgIHVwZGF0ZWRBdAogIH0KfQo%3D&tab=api" className="explorer-badge">Open in API Explorer</a>
<a href="https://explorer.swan.io?query=bXV0YXRpb24gR2VuZXJhdGVBY2NvdW50U3RhdGVtZW50IHsKICBnZW5lcmF0ZUFjY291bnRTdGF0ZW1lbnQoCiAgICBpbnB1dDogewogICAgICBhY2NvdW50SWQ6ICIkQUNDT1VOVF9JRCIKICAgICAgb3BlbmluZ0RhdGU6ICIyMDI0LTA0LTEyVDAwOjAwOjAwLjAwMFoiCiAgICAgIGNsb3NpbmdEYXRlOiAiMjAyNC0wNi0xMlQwMDowMDowMC4wMDBaIgogICAgICBsYW5ndWFnZTogbmwKICAgICAgZm9ybWF0OiBQREYKICAgIH0KICApIHsKICAgIGNsb3NpbmdEYXRlCiAgICBjcmVhdGVkQXQKICAgIGZlZUNyZWRpdHMgewogICAgICBjdXJyZW5jeQogICAgICB2YWx1ZQogICAgfQogICAgZmVlRGViaXRzIHsKICAgICAgY3VycmVuY3kKICAgICAgdmFsdWUKICAgIH0KICAgIGlkCiAgICBvcGVuaW5nRGF0ZQogICAgcGVyaW9kCiAgICBzdGF0dXNJbmZvIHsKICAgICAgc3RhdHVzCiAgICB9CiAgICB1cGRhdGVkQXQKICB9Cn0K" className="explorer-badge">Open in API Explorer</a>

```graphql {4-8} showLineNumbers
```graphql {4-8,13-20,23-26} showLineNumbers
mutation GenerateAccountStatement {
generateAccountStatement(
input: {
accountId: "$ACCOUNT_ID"
openingDate: "2024-04-12T00:00:00.000Z"
closingDate: "2024-06-12T00:00:00.000Z"
language: nl
statementType: PDF
format: PDF
}
) {
closingDate
createdAt
fees {
feeCredits {
currency
value
}
feeDebits {
currency
value
}
id
openingDate
period
status
statusInfo {
status
}
updatedAt
}
}

```

### Payload {#payload}

The mutation returns all of the requested information.
Notice the `period` = `Custom` (line 12), indicating that you generated this account statement, not Swan.
The `period` field shows `Custom` (line 16) for on-demand statements. Swan automatically generates statements with `period` values of `Monthly` or `Custom`.

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

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

### Retrieve generated statement {#retrieve}

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.
1. Add the account statement `id`.
1. Add `statusInfo` for all statuses. The URL to download the statement is provided in `statusInfo` > `GeneratedStatusInfo` > `url` (line 11).

<a href="https://explorer.swan.io?query=cXVlcnkgR2V0QWNjb3VudFN0YXRlbWVudCB7CiAgYWNjb3VudFN0YXRlbWVudChpZDogIiRBQ0NPVU5UX1NUQVRFTUVOVF9JRCIpIHsKICAgIGNsb3NpbmdEYXRlCiAgICBjcmVhdGVkQXQKICAgIGlkCiAgICBvcGVuaW5nRGF0ZQogICAgcGVyaW9kCiAgICBzdGF0dXNJbmZvIHsKICAgICAgc3RhdHVzCiAgICAgIC4uLiBvbiBHZW5lcmF0ZWRTdGF0dXNJbmZvIHsKICAgICAgICBzdGF0dXMKICAgICAgICB1cmwKICAgICAgfQogICAgICAuLi4gb24gUGVuZGluZ1N0YXR1c0luZm8gewogICAgICAgIHN0YXR1cwogICAgICB9CiAgICAgIC4uLiBvbiBGYWlsZWRTdGF0dXNJbmZvIHsKICAgICAgICBzdGF0dXMKICAgICAgfQogICAgICAuLi4gb24gVm9pZGVkU3RhdHVzSW5mbyB7CiAgICAgICAgc3RhdHVzCiAgICAgICAgdXJsCiAgICAgIH0KICAgIH0KICAgIHVwZGF0ZWRBdAogIH0KfQo=" className="explorer-badge">Open in API Explorer</a>

```graphql {2,9,11} showLineNumbers
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 {#retrieve-payload}

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

1. Copy the `url` from the payload.
1. Paste the `url` into your preferred browser.
1. The document downloads automatically after you press enter.

```json {8,12} showLineNumbers
{
"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"
}
}
}
```

:::caution 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. Generate a new statement.
- **`Voided`**: The statement has been voided. A voided statement `url` is still available for reference.
:::

## Dashboard {#dashboard}

You can also generate statements from your Dashboard.
Expand All @@ -81,13 +171,13 @@ You can also generate statements from your Dashboard.

![Screenshot of the Dashboard Account statements tab](../../../images/topics/accounts/statement-generate-1.png)

5. Enter the start date and closing date. The time period can cover **up to three months**.
5. Enter the opening date and closing date. The time period can cover **up to three months**.
1. Choose the format and language.
1. Click **Save**.

![Screenshot of Dashboard modal to generate an account statement](../../../images/topics/accounts/statement-generate-2.png)

Your new statement appears on your list of account statements with the status `Pending`.
After the status changes to `Available`, you can download your statement.
After the status changes to `Generated`, you can download your statement.

![Screenshot of new account statement line with pending status](../../../images/topics/accounts/statement-generate-3.png)