Add a file to a draft

.md

Hang a file on a draft, to go out with its send.

Scopesmail:write
POST/v1/me/mail/drafts/{id}/attachments

A file goes onto a draft that already exists, so save a draft first and use its id, such as msg_q9w3k7x2n8m4t6vb. The file then goes out with the send of that draft, and it is on the draft wherever the draft is opened, the browser included.

The file travels as base64 inside JSON. Every write in this API is JSON, so an upload is too.

Request

curl -X POST https://api.proppertrading.com/v1/me/mail/drafts/msg_q9w3k7x2n8m4t6vb/attachments \
  -H "Authorization: Bearer ptat_9f2c1a44_3b8e7d2f5c9a1b4e6d8f0a2c4e6b8d1f" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 7d1e3a90-4b2c-4f6e-9a8d-1c3e5f7a9b0d" \
  -d '{
    "name": "statement-july.pdf",
    "data": "JVBERi0xLjcKJeLjz9MK..."
  }'
FieldDescription
nameWhat the recipient sees the file called. Never used as a path on our side
dataThe file, base64. At most 8 MB once decoded

The type is worked out from the bytes. There is no field for it, because a type the sender chose is a type nobody should trust.

Response

201, with every file now on the draft, oldest first:

{
    "data": [
        {
            "id": "att_n6q2w8k4t9x3m7hr",
            "name": "statement-july.pdf",
            "content_type": "application/pdf",
            "size_bytes": 84213
        }
    ],
    "meta": {
        "request_id": "req_01kz4bkr1aj1gv63d8fv3133ey",
        "has_more": false,
        "next_cursor": null
    }
}

Retrying with the same Idempotency-Key answers the same list and adds nothing. A second file is a new key.

Errors

StatusCodeMeaning
400missing_idempotency_keyEvery POST needs one
400not_a_draftThe message is not a draft, or not any more
400invalid_attachmentdata is not base64, or it is empty
400attachment_too_largeMore than 8 MB once decoded
403insufficient_scopeThis device does not hold mail:write
404resource_not_foundNo such message in a mailbox you can read. A number in the path finds none either
422validation_failedname or data missing