Skip to content

Add v2 returned letters endpoints#4905

Draft
BlessedDev wants to merge 4 commits into
mainfrom
add_v2_returned_letters_endpoints
Draft

Add v2 returned letters endpoints#4905
BlessedDev wants to merge 4 commits into
mainfrom
add_v2_returned_letters_endpoints

Conversation

@BlessedDev

Copy link
Copy Markdown
Contributor

No description provided.

 This endpoint returns the existing returned letters summaries for a service. This is the same data that
 is available in the service's dashboard, which is the number of returned letters for each report_date.
 For security purposes, this endpint is only accesible by a live API key.
 This endpoint returns the same returned letters report displayed in a service's dashboard
 for a given report date.
 Returned letter summaries are added periodically if at all, so it is more efficient to cache the data.
 TTL is set to 24hrs.
Comment thread app/dao/returned_letters_dao.py Outdated
result = [
{
"notification_id": str(row["notification_id"]),
"reference": row["client_reference"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different to what we send in the callback:

"reference": returned_letter["reference"],

We should make a .serialize() method to guarantee the callback and report are using the same schema and then we only have to document it once

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback data is pre processed here

"reference": returned_letter_data["client_reference"] if returned_letter_data["api_key_id"] else None,

So both the report and the callback data present "reference" to the end user instead of "client_reference".

I explored the .serialize() option initially but the data is collated from a few other tables as well so it is not a perfect fit.

I am thinking of a follow up PR to tie the callback and endpoints data together.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user receives a field calledreference in both cases. The problem is that in one case the data is coming from the client_reference column in the database and in the other it’s coming from the reference column in the database. The former is the reference the user provides us, the latter is our internal reference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like both fetch_returned_letters and fetch_returned_letter_callback_data_dao return the client_reference from the database:

table.client_reference,

table.client_reference,

However this shows that the current architecture is not very clear and I will look at refactoring what we have by implementing something similar to a .serialize() that will be used by the admin, callback and GET endpoint.

It will have to go on the back burner for now because of other priorities.

@BlessedDev BlessedDev force-pushed the add_v2_returned_letters_endpoints branch from fa867b9 to f8bf10f Compare July 3, 2026 12:34
 Returned letter summaries are added periodically if at all, it is more efficient to cache the data.
 TTL is set to 24hrs
@BlessedDev BlessedDev force-pushed the add_v2_returned_letters_endpoints branch from f8bf10f to 32837eb Compare July 3, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants