Skip to content

Newsletter Subscriber Serializer Documentation


Description

This API endpoint allows users to subscribe to a newsletter. Upon successful subscription, a thank-you email is sent to the subscriber.


Request

Headers:

  • Content-Type: application/json
  • Authorization: Not required (publicly accessible).

Body Parameters:

Field Type Required Description
email string Yes Email address of the user.
Example Request:
{
    "email": "user@example.com"
}

Response

On Success:

Status Code: 201 CREATED

Body:

{
    "success": "Subscription successful"
}

On Failure:

Status Code: 400 BAD REQUEST

Body (Example):

{
    "email": ["Enter a valid email address."]
}


Error Responses

Status Code Reason Example Body
400 Validation Error {"email": ["Enter a valid email address."]}
500 Server Error {"error": "An unexpected error occurred."}

Permissions

This endpoint is publicly accessible and does not require authentication.


Functionality

  1. Validates the provided email using the NewsLetterSubscriberSerializer.
  2. Saves the subscriber's email to the database.
  3. Sends a thank-you email asynchronously using the send_email task.