# Pix Statement

A Pix Statement allows you to request a detailed report of all Pix transactions in your account for a given period.

A statement must be created before it can be read, and this feature is only available for direct Pix participants.

Here we will show you how to create and manage them.

### The Pix Statement Object

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `id` | STRING | Unique id for the Pix statement. |
| `after` | STRING | Start date of the statement period. |
| `before` | STRING | End date of the statement period. |
| `type` | STRING | Type of the statement. Options: "interchange", "interchangeTotal", "transaction". |
| `status` | STRING | Current status. Options: "created", "looking", "success", "failed". |
| `chunkCount` | INTEGER | Number of chunks the statement file is split into. Each chunk can be downloaded individually. |
| `transactionCount` | INTEGER | Number of transactions in the statement. |
| `created` | STRING | Creation datetime. Example: "2020-04-23T23:00:00.000000+00:00". |
| `updated` | STRING | Last update datetime. Example: "2020-04-23T23:00:00.000000+00:00". |

### Create a Pix Statement

`POST /v2/pix-statement`

Request a Pix statement for a specific period and type.

The after and before parameters must name the same single day the statement covers. For type "interchange" or "interchangeTotal", that day must be the first day of a past month (after = before = "2022-01-01"). For type "transaction", after and before may be full timestamps up to 24 hours apart.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `after` | REQUIRED | Start date of the statement period. Example: "2022-01-01". |
| `before` | REQUIRED | End date of the statement period. Example: "2022-01-01". |
| `type` | REQUIRED | Type of the statement. Options: "interchange", "interchangeTotal", "transaction". |

**Request**

```python
import starkinfra

statement = starkinfra.pixstatement.create(
    starkinfra.PixStatement(
        after="2022-01-01",
        before="2022-01-31",
        type="transaction"
    )
)

print(statement)
```

**Response**

```python
PixStatement(
    id="5656565656565656",
    after="2022-01-01",
    before="2022-01-31",
    type="transaction",
    status="created",
    chunk_count=0,
    transaction_count=0,
    created="2022-01-01T00:00:00+00:00",
    updated="2022-01-01T00:00:00+00:00"
)
```

### List Pix Statements

`GET /v2/pix-statement`

List and filter all Pix statements. Results are paged.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `cursor` | OPTIONAL | String used to get the next batch of results. |
| `ids` | OPTIONAL | List of strings to get specific entities by ids. |
| `limit` | OPTIONAL | Number of results per cursor. Max = 100. |

**Request**

```python
import starkinfra

statements = starkinfra.pixstatement.query(limit=10)

for statement in statements:
    print(statement)
```

**Response**

```python
<generator object query at 0x...>

PixStatement(
    id="5656565656565656",
    after="2022-01-01",
    before="2022-01-31",
    type="transaction",
    status="success",
    chunk_count=2,
    transaction_count=150,
    created="2022-01-01T00:00:00+00:00",
    updated="2022-01-01T00:05:00+00:00"
)
```

### Get a Pix Statement

`GET /v2/pix-statement/:id`

Get a single Pix statement by its id.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the Pix statement entity. |
| `fields` | OPTIONAL | List of strings to filter response JSON keys. Not available in the SDKs. |

**Request**

```python
import starkinfra

statement = starkinfra.pixstatement.get("5656565656565656")

print(statement)
```

**Response**

```python
PixStatement(
    id="5656565656565656",
    after="2022-01-01",
    before="2022-01-31",
    type="transaction",
    status="success",
    chunk_count=2,
    transaction_count=150,
    created="2022-01-01T00:00:00+00:00",
    updated="2022-01-01T00:05:00+00:00"
)
```

### Get a Pix Statement CSV

`GET /v2/pix-statement/:id/csv`

Get the CSV file for a completed Pix statement. The file is returned compressed in the gzip format.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the Pix statement entity. |

**Request**

```python
import starkinfra

csv = starkinfra.pixstatement.csv("5656565656565656")

with open("statement.zip", "wb") as f:
    f.write(csv)
```

**Response**

```python
<bytes: statement zip file content>
```

### Get a Pix Statement Chunk

`GET /v2/pix-statement/:id/chunk/:number`

Get a single chunk of a completed Pix statement. Large statements are split into numbered parts, letting you download one chunk at a time. The chunk is returned compressed in the gzip format.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the Pix statement entity. |
| `number` | REQUIRED | Number of the chunk to retrieve, ranging from 1 to the statement's chunkCount. |

**Request**

```python
import starkinfra

response = starkinfra.request.get("/pix-statement/5656565656565656/chunk/1")

with open("statement-chunk-1.csv.gz", "wb") as f:
    f.write(response.content)
```

**Response**

```python
<bytes: statement chunk content>
```

## Available Languages

Code samples on this page are in Python. The same content is available with samples in:

- [Python](https://docs.starkinfra.com/api/v2/pix-statement-python.md)
- [Node.js](https://docs.starkinfra.com/api/v2/pix-statement-node.md)
- [PHP](https://docs.starkinfra.com/api/v2/pix-statement-php.md)
- [Java](https://docs.starkinfra.com/api/v2/pix-statement-java.md)
- [Ruby](https://docs.starkinfra.com/api/v2/pix-statement-ruby.md)
- [Elixir](https://docs.starkinfra.com/api/v2/pix-statement-elixir.md)
- [.NET](https://docs.starkinfra.com/api/v2/pix-statement-dotnet.md)
- [Go](https://docs.starkinfra.com/api/v2/pix-statement-go.md)
- [Clojure](https://docs.starkinfra.com/api/v2/pix-statement-clojure.md)
- [cURL](https://docs.starkinfra.com/api/v2/pix-statement-curl.md)
