Skip to content

resources

Monzo API 'attachments' resource.

AttachmentsResource dataclass

Bases: BaseResource

Monzo API 'attachments' resource.

Note

Monzo API docs: https://docs.monzo.com/#attachments

Source code in pymonzo/attachments/resources.py
 7
 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
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
class AttachmentsResource(BaseResource):
    """Monzo API 'attachments' resource.

    Note:
        Monzo API docs: https://docs.monzo.com/#attachments
    """

    def upload(
        self,
        *,
        file_name: str,
        file_type: str,
        content_length: int,
    ) -> MonzoAttachmentResponse:
        """Upload an attachment.

        The response will include a `file_url` which will be the URL of the resulting
        file, and an `upload_url` to which the file should be uploaded to.

        Note:
            Monzo API docs: https://docs.monzo.com/#upload-attachment

        Arguments:
            file_name: The name of the file to be uploaded.
            file_type: The content type of the file.
            content_length: The HTTP Content-Length of the upload request body,
                in bytes.

        Returns:
            Response with `file_url` which will be the URL of the resulting file,
            and an `upload_url` to which the file should be uploaded to.
        """
        endpoint = "/attachment/upload"
        data = {
            "file_name": file_name,
            "file_type": file_type,
            "content_length": content_length,
        }
        response = self._get_response(method="post", endpoint=endpoint, data=data)

        attachment_response = MonzoAttachmentResponse(**response.json())

        return attachment_response

    def register(
        self,
        transaction_id: str,
        *,
        file_url: str,
        file_type: str,
    ) -> MonzoAttachment:
        """Register uploaded image to an attachment.

        Note:
            Monzo API docs: https://docs.monzo.com/#register-attachment

        Arguments:
            transaction_id: The ID of the transaction to associate the attachment with.
            file_url: The URL of the uploaded attachment.
            file_type: The content type of the attachment.

        Returns:
            A Monzo attachment.
        """
        endpoint = "/attachment/register"
        data = {
            "external_id": transaction_id,
            "file_url": file_url,
            "file_type": file_type,
        }
        response = self._get_response(method="post", endpoint=endpoint, data=data)

        attachment = MonzoAttachment(**response.json()["attachment"])

        return attachment

    def deregister(self, attachment_id: str) -> dict:
        """Deregister an attachment.

        Note:
            Monzo API docs: https://docs.monzo.com/#deregister-attachment

        Arguments:
            attachment_id: The ID of the attachment to deregister.

        Returns:
            API response.
        """
        endpoint = "/attachment/deregister"
        data = {"id": attachment_id}
        response = self._get_response(method="post", endpoint=endpoint, data=data)

        return response.json()

deregister(attachment_id)

Deregister an attachment.

Note

Monzo API docs: https://docs.monzo.com/#deregister-attachment

Parameters:

Name Type Description Default
attachment_id str

The ID of the attachment to deregister.

required

Returns:

Type Description
dict

API response.

Source code in pymonzo/attachments/resources.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def deregister(self, attachment_id: str) -> dict:
    """Deregister an attachment.

    Note:
        Monzo API docs: https://docs.monzo.com/#deregister-attachment

    Arguments:
        attachment_id: The ID of the attachment to deregister.

    Returns:
        API response.
    """
    endpoint = "/attachment/deregister"
    data = {"id": attachment_id}
    response = self._get_response(method="post", endpoint=endpoint, data=data)

    return response.json()

register(transaction_id, *, file_url, file_type)

Register uploaded image to an attachment.

Note

Monzo API docs: https://docs.monzo.com/#register-attachment

Parameters:

Name Type Description Default
transaction_id str

The ID of the transaction to associate the attachment with.

required
file_url str

The URL of the uploaded attachment.

required
file_type str

The content type of the attachment.

required

Returns:

Type Description
MonzoAttachment

A Monzo attachment.

Source code in pymonzo/attachments/resources.py
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
def register(
    self,
    transaction_id: str,
    *,
    file_url: str,
    file_type: str,
) -> MonzoAttachment:
    """Register uploaded image to an attachment.

    Note:
        Monzo API docs: https://docs.monzo.com/#register-attachment

    Arguments:
        transaction_id: The ID of the transaction to associate the attachment with.
        file_url: The URL of the uploaded attachment.
        file_type: The content type of the attachment.

    Returns:
        A Monzo attachment.
    """
    endpoint = "/attachment/register"
    data = {
        "external_id": transaction_id,
        "file_url": file_url,
        "file_type": file_type,
    }
    response = self._get_response(method="post", endpoint=endpoint, data=data)

    attachment = MonzoAttachment(**response.json()["attachment"])

    return attachment

upload(*, file_name, file_type, content_length)

Upload an attachment.

The response will include a file_url which will be the URL of the resulting file, and an upload_url to which the file should be uploaded to.

Note

Monzo API docs: https://docs.monzo.com/#upload-attachment

Parameters:

Name Type Description Default
file_name str

The name of the file to be uploaded.

required
file_type str

The content type of the file.

required
content_length int

The HTTP Content-Length of the upload request body, in bytes.

required

Returns:

Type Description
MonzoAttachmentResponse

Response with file_url which will be the URL of the resulting file,

MonzoAttachmentResponse

and an upload_url to which the file should be uploaded to.

Source code in pymonzo/attachments/resources.py
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
def upload(
    self,
    *,
    file_name: str,
    file_type: str,
    content_length: int,
) -> MonzoAttachmentResponse:
    """Upload an attachment.

    The response will include a `file_url` which will be the URL of the resulting
    file, and an `upload_url` to which the file should be uploaded to.

    Note:
        Monzo API docs: https://docs.monzo.com/#upload-attachment

    Arguments:
        file_name: The name of the file to be uploaded.
        file_type: The content type of the file.
        content_length: The HTTP Content-Length of the upload request body,
            in bytes.

    Returns:
        Response with `file_url` which will be the URL of the resulting file,
        and an `upload_url` to which the file should be uploaded to.
    """
    endpoint = "/attachment/upload"
    data = {
        "file_name": file_name,
        "file_type": file_type,
        "content_length": content_length,
    }
    response = self._get_response(method="post", endpoint=endpoint, data=data)

    attachment_response = MonzoAttachmentResponse(**response.json())

    return attachment_response