Skip to content

Transactions Pydantic Models

In order to simplify and standardize the data that is passed between the client and the Revolut Business API, PyRevolut uses Pydantic models to define the structure of the data. Below are the Pydantic models used by the Transactions endpoint.


ResourceTransaction

Bases: BaseModel

Transaction resource model.

Source code in pyrevolut/api/transactions/resources/transaction.py
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
class ResourceTransaction(BaseModel):
    """
    Transaction resource model.
    """

    class ModelMerchant(BaseModel):
        """The information about the merchant (only for card transfers)"""

        name: Annotated[str, Field(description="The name of the merchant.")]
        city: Annotated[str, Field(description="The city of the merchant.")]
        category_code: Annotated[
            str, Field(description="The category code of the merchant.")
        ]
        country: Annotated[
            CountryAlpha2 | CountryAlpha3,
            Field(
                description="The country of the merchant as the 2-letter ISO 3166 code."
            ),
        ]

    class ModelLeg(BaseModel):
        """
        The legs of the transaction:

            - For transactions between your Revolut accounts,
            there can be 2 legs, for example, an internal transfer made out of
            the GBP account and into the EUR account.

            - For transactions in other cases, there is only 1 leg.
        """

        class ModelCounterparty(BaseModel):
            """The counterparty of the transaction."""

            account_id: Annotated[
                UUID | None,
                Field(description="The ID of the counterparty account."),
            ] = None
            account_type: Annotated[
                EnumAccountType,
                Field(description="Indicates the type of the account."),
            ]
            id: Annotated[
                UUID | None,
                Field(description="The ID of the counterparty."),
            ] = None

        leg_id: Annotated[UUID, Field(description="The ID of the leg.")]
        amount: Annotated[
            float,
            Field(description="The amount of the transaction leg."),
        ]
        fee: Annotated[
            float | None,
            Field(description="The amount of the transaction leg fee."),
        ] = None
        currency: Annotated[
            Currency,
            Field(description="ISO 4217 currency code in upper case."),
        ]
        bill_amount: Annotated[
            float | None,
            Field(description="The billing amount for cross-currency payments."),
        ] = None
        bill_currency: Annotated[
            Currency | None,
            Field(description="The billing currency for cross-currency payments."),
        ] = None
        account_id: Annotated[
            UUID,
            Field(
                description="The ID of the account that the transaction leg is associated with."
            ),
        ]
        counterparty: Annotated[
            ModelCounterparty | None,
            Field(description="The counterparty of the transaction leg."),
        ] = None
        description: Annotated[
            str | None,
            Field(description="The transaction leg purpose."),
        ] = None
        balance: Annotated[
            float | None,
            Field(
                description="The total balance of the account that the transaction is associated with."
            ),
        ] = None

    class ModelCard(BaseModel):
        """The card details (only for card transfers)."""

        card_number: Annotated[
            str,
            Field(description="The masked card number."),
        ]
        first_name: Annotated[
            str | None,
            Field(description="The first name of the cardholder."),
        ] = None
        last_name: Annotated[
            str | None,
            Field(description="The last name of the cardholder."),
        ] = None
        phone: Annotated[
            PhoneNumber | None,
            Field(
                description="The phone number of the cardholder in the E.164 format."
            ),
        ] = None

    id: Annotated[UUID, Field(description="The ID of the transaction.")]
    type: Annotated[
        EnumTransactionType, Field(description="Indicates the transaction type.")
    ]
    request_id: Annotated[
        str | None,
        Field(
            description="The request ID that you provided previously.",
        ),
    ] = None
    state: Annotated[
        EnumTransactionState, Field(description="Indicates the transaction state.")
    ]
    reason_code: Annotated[
        str | None,
        Field(
            description="The reason code when the transaction state is declined or failed."
        ),
    ] = None
    created_at: Annotated[
        DateTime,
        Field(
            description="The date and time the transaction was created in ISO 8601 format."
        ),
    ]
    updated_at: Annotated[
        DateTime,
        Field(
            description="The date and time the transaction was last updated in ISO 8601 format."
        ),
    ]
    completed_at: Annotated[
        DateTime | None,
        Field(
            description="""
            The date and time the transaction was completed in ISO 8601 format. 
            This is required when the transaction state is completed.
            """
        ),
    ] = None
    scheduled_for: Annotated[
        Date | None,
        Field(
            description="""
            The scheduled date of the payment, if applicable. Provided in ISO 8601 format.
            """
        ),
    ] = None
    related_transaction_id: Annotated[
        UUID | None,
        Field(description="The ID of the original transaction that has been refunded."),
    ] = None
    merchant: Annotated[
        ModelMerchant | None,
        Field(
            description="The information about the merchant (only for card transfers)."
        ),
    ] = None
    reference: Annotated[
        str | None,
        Field(description="The reference of the transaction."),
    ] = None
    legs: Annotated[
        list[ModelLeg],
        Field(
            description="""
            The legs of the transaction:

            - For transactions between your Revolut accounts,
            there can be 2 legs, for example, an internal transfer made out of
            the GBP account and into the EUR account.

            - For transactions in other cases, there is only 1 leg.
            """
        ),
    ]
    card: Annotated[
        ModelCard | None,
        Field(description="The card details (only for card transfers)."),
    ] = None

ModelCard

Bases: BaseModel

The card details (only for card transfers).

Source code in pyrevolut/api/transactions/resources/transaction.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
class ModelCard(BaseModel):
    """The card details (only for card transfers)."""

    card_number: Annotated[
        str,
        Field(description="The masked card number."),
    ]
    first_name: Annotated[
        str | None,
        Field(description="The first name of the cardholder."),
    ] = None
    last_name: Annotated[
        str | None,
        Field(description="The last name of the cardholder."),
    ] = None
    phone: Annotated[
        PhoneNumber | None,
        Field(
            description="The phone number of the cardholder in the E.164 format."
        ),
    ] = None

ModelLeg

Bases: BaseModel

The legs of the transaction:

- For transactions between your Revolut accounts,
there can be 2 legs, for example, an internal transfer made out of
the GBP account and into the EUR account.

- For transactions in other cases, there is only 1 leg.
Source code in pyrevolut/api/transactions/resources/transaction.py
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
class ModelLeg(BaseModel):
    """
    The legs of the transaction:

        - For transactions between your Revolut accounts,
        there can be 2 legs, for example, an internal transfer made out of
        the GBP account and into the EUR account.

        - For transactions in other cases, there is only 1 leg.
    """

    class ModelCounterparty(BaseModel):
        """The counterparty of the transaction."""

        account_id: Annotated[
            UUID | None,
            Field(description="The ID of the counterparty account."),
        ] = None
        account_type: Annotated[
            EnumAccountType,
            Field(description="Indicates the type of the account."),
        ]
        id: Annotated[
            UUID | None,
            Field(description="The ID of the counterparty."),
        ] = None

    leg_id: Annotated[UUID, Field(description="The ID of the leg.")]
    amount: Annotated[
        float,
        Field(description="The amount of the transaction leg."),
    ]
    fee: Annotated[
        float | None,
        Field(description="The amount of the transaction leg fee."),
    ] = None
    currency: Annotated[
        Currency,
        Field(description="ISO 4217 currency code in upper case."),
    ]
    bill_amount: Annotated[
        float | None,
        Field(description="The billing amount for cross-currency payments."),
    ] = None
    bill_currency: Annotated[
        Currency | None,
        Field(description="The billing currency for cross-currency payments."),
    ] = None
    account_id: Annotated[
        UUID,
        Field(
            description="The ID of the account that the transaction leg is associated with."
        ),
    ]
    counterparty: Annotated[
        ModelCounterparty | None,
        Field(description="The counterparty of the transaction leg."),
    ] = None
    description: Annotated[
        str | None,
        Field(description="The transaction leg purpose."),
    ] = None
    balance: Annotated[
        float | None,
        Field(
            description="The total balance of the account that the transaction is associated with."
        ),
    ] = None

ModelCounterparty

Bases: BaseModel

The counterparty of the transaction.

Source code in pyrevolut/api/transactions/resources/transaction.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class ModelCounterparty(BaseModel):
    """The counterparty of the transaction."""

    account_id: Annotated[
        UUID | None,
        Field(description="The ID of the counterparty account."),
    ] = None
    account_type: Annotated[
        EnumAccountType,
        Field(description="Indicates the type of the account."),
    ]
    id: Annotated[
        UUID | None,
        Field(description="The ID of the counterparty."),
    ] = None

ModelMerchant

Bases: BaseModel

The information about the merchant (only for card transfers)

Source code in pyrevolut/api/transactions/resources/transaction.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class ModelMerchant(BaseModel):
    """The information about the merchant (only for card transfers)"""

    name: Annotated[str, Field(description="The name of the merchant.")]
    city: Annotated[str, Field(description="The city of the merchant.")]
    category_code: Annotated[
        str, Field(description="The category code of the merchant.")
    ]
    country: Annotated[
        CountryAlpha2 | CountryAlpha3,
        Field(
            description="The country of the merchant as the 2-letter ISO 3166 code."
        ),
    ]

RetrieveListOfTransactions

Retrieve the historical transactions based on the provided query criteria.

The transactions are sorted by the created_at date in reverse chronological order, and they're paginated. The maximum number of transactions returned per page is specified by the count parameter. To get the next page of results, make a new request and use the created_at date from the last item of the previous page as the value for the to parameter.

Note

The API returns a maximum of 1,000 transactions per request.

Note

To be compliant with PSD2 SCA regulations, businesses on the Revolut Business Freelancer plans can only access information older than 90 days within 5 minutes of the first authorisation.

Source code in pyrevolut/api/transactions/get/retrieve_list_of_transactions.py
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
class RetrieveListOfTransactions:
    """
    Retrieve the historical transactions based on the provided query criteria.

    The transactions are sorted by the created_at date in reverse chronological order,
    and they're paginated. The maximum number of transactions returned per page is specified by the
    count parameter. To get the next page of results, make a new request and use the created_at date
    from the last item of the previous page as the value for the to parameter.

    Note
    ----
    The API returns a maximum of 1,000 transactions per request.

    Note
    ----
    To be compliant with PSD2 SCA regulations, businesses on the Revolut Business Freelancer
    plans can only access information older than 90 days within 5 minutes of the first authorisation.
    """

    ROUTE = "/1.0/transactions"

    class Params(BaseModel):
        """
        The query parameters for the request.
        """

        model_config = ConfigDict(
            populate_by_name=True,
            from_attributes=True,
        )

        from_: Annotated[
            DateTime | Date | None,
            Field(
                description="""
                The date and time you retrieve the historical transactions from, including 
                this date-time. 
                Corresponds to the created_at value of the transaction. 
                Provided in ISO 8601 format.

                Used also for pagination. To get back to the previous page of results, 
                make a new request and use the created_at date from the first item of the 
                current page as the value for the from parameter.
                """
            ),
        ] = None
        to: Annotated[
            DateTime | Date | None,
            Field(
                description="""
                The date and time you retrieve the historical transactions to, excluding 
                this date-time. 
                Corresponds to the created_at value of the transaction. 
                Provided in ISO 8601 format. 
                The default value is the date and time at which you're calling the endpoint.

                Used also for pagination. 
                To get the next page of results, make a new request and use the created_at 
                date from the last item of the previous (current) page as the value for the 
                to parameter.  
                """
            ),
        ] = None
        account: Annotated[
            UUID | None,
            Field(
                description="""
                The ID of the account
                """
            ),
        ] = None
        count: Annotated[
            int | None,
            Field(
                description="""
                The maximum number of the historical transactions to retrieve per page.

                To get the next page of results, make a new request and use 
                the created_at date from the last item of the previous page as the 
                value for the to parameter.   

                If not provided, the default value is 100.             
                """,
                le=1000,
                ge=1,
            ),
        ] = None
        type: Annotated[
            EnumTransactionType | None,
            Field(
                description="""
                The type of the historical transactions to retrieve.
                """
            ),
        ] = None

    class Response(ResourceTransaction):
        """
        The response model for the request.
        """

        pass

Params

Bases: BaseModel

The query parameters for the request.

Source code in pyrevolut/api/transactions/get/retrieve_list_of_transactions.py
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
class Params(BaseModel):
    """
    The query parameters for the request.
    """

    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )

    from_: Annotated[
        DateTime | Date | None,
        Field(
            description="""
            The date and time you retrieve the historical transactions from, including 
            this date-time. 
            Corresponds to the created_at value of the transaction. 
            Provided in ISO 8601 format.

            Used also for pagination. To get back to the previous page of results, 
            make a new request and use the created_at date from the first item of the 
            current page as the value for the from parameter.
            """
        ),
    ] = None
    to: Annotated[
        DateTime | Date | None,
        Field(
            description="""
            The date and time you retrieve the historical transactions to, excluding 
            this date-time. 
            Corresponds to the created_at value of the transaction. 
            Provided in ISO 8601 format. 
            The default value is the date and time at which you're calling the endpoint.

            Used also for pagination. 
            To get the next page of results, make a new request and use the created_at 
            date from the last item of the previous (current) page as the value for the 
            to parameter.  
            """
        ),
    ] = None
    account: Annotated[
        UUID | None,
        Field(
            description="""
            The ID of the account
            """
        ),
    ] = None
    count: Annotated[
        int | None,
        Field(
            description="""
            The maximum number of the historical transactions to retrieve per page.

            To get the next page of results, make a new request and use 
            the created_at date from the last item of the previous page as the 
            value for the to parameter.   

            If not provided, the default value is 100.             
            """,
            le=1000,
            ge=1,
        ),
    ] = None
    type: Annotated[
        EnumTransactionType | None,
        Field(
            description="""
            The type of the historical transactions to retrieve.
            """
        ),
    ] = None

Response

Bases: ResourceTransaction

The response model for the request.

Source code in pyrevolut/api/transactions/get/retrieve_list_of_transactions.py
107
108
109
110
111
112
class Response(ResourceTransaction):
    """
    The response model for the request.
    """

    pass

RetrieveTransaction

Retrieve the details of a specific transaction. The details can include, for example, cardholder details for card payments.

You can retrieve a transaction with its details either by its transaction ID or by the request ID that was provided for this transaction at the time of its creation, for example, when you created a payment.

To retrieve a transaction by its transaction ID, use:

/transaction/{transaction_id}

To retrieve a transaction by a request ID provided at transaction creation, use:

/transaction/{request_id}?id_type=request_id
Source code in pyrevolut/api/transactions/get/retrieve_transaction.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class RetrieveTransaction:
    """
    Retrieve the details of a specific transaction.
    The details can include, for example, cardholder details for card payments.

    You can retrieve a transaction with its details either by its transaction ID
    or by the request ID that was provided for this transaction at the time of its
    creation, for example, when you created a payment.

    To retrieve a transaction by its transaction ID, use:

        /transaction/{transaction_id}

    To retrieve a transaction by a request ID provided at transaction creation, use:

        /transaction/{request_id}?id_type=request_id
    """

    ROUTE = "/1.0/transaction/{id}"

    class Params(BaseModel):
        """
        The query parameters for the request.
        """

        id_type: Annotated[
            Literal["request_id"] | None,
            Field(
                description="""
                The type of the ID you're providing for the transaction retrieval.
                The default value is None, which means that the transaction ID is provided.
                """,
            ),
        ] = None

    class Response(ResourceTransaction):
        """
        The response model for the request.
        """

        pass

Params

Bases: BaseModel

The query parameters for the request.

Source code in pyrevolut/api/transactions/get/retrieve_transaction.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Params(BaseModel):
    """
    The query parameters for the request.
    """

    id_type: Annotated[
        Literal["request_id"] | None,
        Field(
            description="""
            The type of the ID you're providing for the transaction retrieval.
            The default value is None, which means that the transaction ID is provided.
            """,
        ),
    ] = None

Response

Bases: ResourceTransaction

The response model for the request.

Source code in pyrevolut/api/transactions/get/retrieve_transaction.py
43
44
45
46
47
48
class Response(ResourceTransaction):
    """
    The response model for the request.
    """

    pass