Outcome
Your application lists the debtor correspondence of an accepted mandate, reads the text of each email, and stores its PDF rendering and attachments.Prerequisites
- A Bearer key with the
case:correspondence:readscope.*covers it;case:mandates:readalone still lists the history but answers403on the correspondence routes. - The exact mandate UUID — from the claim’s current
mandate_id, theorder.acceptedpayload’smandate_id, ormandate.created.
source_mandate names the track it belongs to.
1. List correspondence
next URL until it is null. Narrow the list with
channel and direction (inbound or outbound). List rows carry the
envelope — subject, occurred_at, direction, the email addresses
(from, to, cc), history_entry_ids, and pdf_url — but no text and no
attachments; read the item for both.
2. Read one item
channelis an open enumeration. It isemailtoday; treat it as a plain string and skip or store items with values your application does not know yet.emailcarries the addresses of an email item.bodyholds the visible text of the new message part intextand quoted earlier messages inquoted_text. The text is projected from the stored mail and is never HTML.complete: falsemeans the text was cut at the size limit or the mail could only be projected partially; the PDF and the attachments remain the full record.bodyisnullwhen no body is stored.attachments[]lists the files of the email.idis an opaque string, not a UUID.statusisavailableorunavailable(open enumeration):availablecomes with adownload_url;unavailablemeans the mail structure does not allow a download, sodownload_urlisnull. Keep the metadata of an unavailable attachment, and of any status your application does not know yet, without attempting a download.size_bytesisnullwhen the mail does not declare it.history_entry_idsnames the published history entries that surface this email. It is empty for an email reachable only through a client request.
3. Download the PDF and the attachments
404.
download_url of an available attachment, or build the route from
its opaque id. The response’s Content-Type is detected from the bytes and
is never taken from the mail, so it can differ from the declared mime_type;
store the file by the detected type. Every download is sent with
Content-Disposition: attachment and a sanitised filename — never render an
attachment inline in a browser context. Unknown and unavailable attachments
answer 404.
Representative response
CorrespondenceDetail.
Incremental reads
Useupdated_since for incremental reads, exactly as for the
case history. The
cutoff is inclusive and rows expose updated_at, so persist the greatest
applied timestamp, overlap the next sweep, and upsert items by id, keeping
their newest version. An item becomes readable through a status or
client-request publication; that moment counts as an update, so
updated_since also returns newly readable items. With a cutoff, rows are ordered by updated_at and then
id and the next URL carries an opaque cursor; follow it exactly. Items
changed less than a minute ago are held back until they settle. Only advance
the saved timestamp after every page has been applied. Follow the shared
pagination and synchronization guidance
for overlap windows and recovery after an interrupted read.
History links and webhooks
A history entry’srelated_resources[] reference of type email links to the
correspondence item in url; the reference’s url is null when paywise
keeps no stored copy of that email. With
expand=history.related_resources, the expanded email body also carries
correspondence_url.
Subscribe to mandate.correspondence.published to learn when an item first
becomes readable — through a published status or a client request. The event
is sent once per item; its data carries company_id, mandate_id,
mandate_url, correspondence_id, correspondence_url, and channel. Fetch
correspondence_url and upsert by correspondence_id. See
Webhook events.
Runnable Python workflow
Python workflow
next iterator for a full sweep. Attachment downloads are authenticated:
retain the Bearer header, and validate that a returned download_url stays on
the API HTTPS origin before sending it.
Failure and recovery
403: the key lackscase:correspondence:read. Grant the scope in the developer portal;case:mandates:readalone is not enough.404: verify the selected company, the exact mandate UUID, and the item ID. Unknown items and items of another company answer404alike. On the PDF route,404also means no body is stored; on the attachment route, the attachment is unknown orunavailable.400 invalid_parameteron the list: use the documented filters and values.429: wait at leastRetry-After, then resume from the exact last uncommittednextURL.503on a download: the document storage was briefly unavailable. Retry afterRetry-Afterseconds.
