Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: allow single CC/BCC recipient to be sent via form-data #2286

Merged

Conversation

kevinkim-ogp
Copy link
Contributor

Problem

Unable to send a single CC/BCC recipient when calling the transactional email API with form-data. This appears to be an edge case, as there are no issues when sending multiple CC/BCC recipients using form-data.

// how we normally append CC/BCC with more than 1 recipient
// this is accepted
formData.append('cc', '[email protected]')
formData.append('cc', '[email protected]')

// BUT fails when only 1 recipient, api validation interprets this as a string
// returning error message 'cc must be an array'
formData.append('cc', '[email protected]')


// other alternatives that were tested but not allowed by api
formData.append('cc[]', '[email protected]')
formData.append('cc', ['[email protected]'])  // form-data does not accept arrays
formData.append('cc', JSON.stringify(['[email protected]']))  // api does not accept stringified arrays

Note: Postman requires attachments to be sent via form-data

Related issue highlighted by another user: #2140

Solution

Enhance current CC/BCC validation to accept stringified arrays.
This change ensures:

  • Compatibility with direct array submissions (existing implementation).
  • Compatibility with form-data, where cc can be sent as a stringified JSON array.

@kevinkim-ogp kevinkim-ogp changed the title Fix/form data cc bcc single recipient Fix: allow single CC/BCC recipient to be sent via form-data Nov 21, 2024
@jia1
Copy link
Member

jia1 commented Nov 22, 2024

Thanks @kevinkim-ogp!

I ran your branch on my local machine and specifying ["[email protected]"] works for me.

I'll take a look at the code right now.

Copy link
Member

@jia1 jia1 left a comment

Choose a reason for hiding this comment

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

Thank you, @kevinkim-ogp! Just need a bit of tidying up on your end and then this should be good to go.

Copy link
Member

@jia1 jia1 left a comment

Choose a reason for hiding this comment

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

LGTM, will let you know once we get this deployed

@jia1 jia1 merged commit f7d3ecb into opengovsg:master Nov 25, 2024
5 checks passed
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