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

1544 New subscriber endpoint (part 1) #1545

Merged
merged 9 commits into from
Oct 16, 2024

Conversation

dhochbaum-dcp
Copy link
Collaborator

@dhochbaum-dcp dhochbaum-dcp commented Oct 8, 2024

Add new endpoint to ZAP Search API that creates a new contact in SendGrid and adds that user to the List for the current ZAP Search environment.

New endpoint should exist as a POST to /subscribers and take in a POST body with shape:

{
  "email": "[email protected]"
}
  • Add SendGrid API key to ZAP Search back end as environment variable. API Key is availabe in SendGrid 1PW vault under "ZAP Search Staging SendGrid API Key"
  • Add environment-specific List ID as environment variable

List names are zap-subscribers-staging for staging and zap-subscribers-production for production.

Validation

The endpoint should perform the following validations on the supplied POST body and return the given error codes

  • Confirm that provided email is a valid email address string. If invalid, return 400 Bad Request error response
  • Confirm that supplied email address is not already a subscriber. Because we use SG in other projects, we can't rely on simply looking for a SG contact with the supplied email. Instead, a subscriber is considered to already exist if we have a contact with the given email and that email is already on the list for the current environment. If subscriber already exists, return 409 Conflict error response

Adding subscriber

  • Given a call with valid data, a contact is added to SG and the contact is added to the correct List. Return 200 success response code.

Once data is validated, the subscriber should be created and added to the list. See SendGrid docs for adding/updating a contact here. Note that request body can take in List IDs that the contact should be added to.

Note the following from SG's docs describing how contact creation is an asynchronous process:

Because the creation and update of contacts is an asynchronous process, the response will not contain immediate feedback on the processing of your upserted contacts. Rather, it will contain an HTTP 202 response indicating the contacts are queued for processing or an HTTP 4XX error containing validation errors. Should you wish to get the resulting contact's ID or confirm that your contacts have been updated or added, you can use the Get Contacts by Identifiers operation.

Our endpoint should still be synchronous, so endpoint code may require implementing polling with a max wait time. Let's start with 3 seconds and see how fast SG's APIs are.

Completes #1544

Copy link

netlify bot commented Oct 8, 2024

Deploy Preview for labs-zap ready!

Name Link
🔨 Latest commit 98cfddd
🔍 Latest deploy log https://app.netlify.com/sites/labs-zap/deploys/671022c4de2433000801ec45
😎 Deploy Preview https://deploy-preview-1545--labs-zap.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

server/src/subscription/subscription.controller.ts Outdated Show resolved Hide resolved
server/src/subscription/subscription.controller.ts Outdated Show resolved Hide resolved
server/src/subscription/subscription.controller.ts Outdated Show resolved Hide resolved
server/src/subscription/subscription.controller.ts Outdated Show resolved Hide resolved
@dhochbaum-dcp dhochbaum-dcp marked this pull request as ready for review October 9, 2024 19:22
@dhochbaum-dcp dhochbaum-dcp requested a review from a team as a code owner October 9, 2024 19:22
server/src/subscriber/subscriber.service.ts Outdated Show resolved Hide resolved
server/src/subscriber/subscriber.controller.ts Outdated Show resolved Hide resolved
@dhochbaum-dcp dhochbaum-dcp merged commit 150912b into develop Oct 16, 2024
5 checks passed
@dhochbaum-dcp dhochbaum-dcp deleted the 1544/new-subscriber-endpoint branch October 16, 2024 20:43
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