Skip to content

PragatiVerma18/BiteSpeed

Repository files navigation

Contact Identification API

This is a Django REST API for identifying and managing contacts based on email and phone numbers. It determines the primary and secondary contacts linked to a given email or phone number.

Task URL - Bitespeed Backend Task: Identity Reconciliation

🚀 Features

  • Identify contacts based on email or phone number.
  • Maintain primary and secondary contact relationships.
  • Provide a structured response with all associated contact details.

📌 Tech Stack

  • Python (Django, Django REST Framework)
  • PostgreSQL (or SQLite for local development)
  • drf-yasg (Swagger API Documentation)

🛠️ Setup and Installation

1️⃣ Clone the Repository

git clone https://github.com/PragatiVerma18/BiteSpeed.git

2️⃣ Create and Activate a Virtual Environment

python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`

3️⃣ Install Dependencies

pip install -r requirements.txt

4️⃣ Apply Migrations

python manage.py migrate

5️⃣ Create a Superuser (for Django Admin)

python manage.py createsuperuser

6️⃣ Setup environment variables in .env

DEBUG=
DATABASE_URL=
SECRET_KEY=

7️⃣ Run the Development Server

python manage.py runserver

The API will be available at http://127.0.0.1:8000/

8️⃣ Run Tests

pytest identity_reconciliation/tests/test_identify.py -v

📖 API Documentation

🔍 Identify Contact API

Endpoint:

POST /identify/

Description:

Identifies primary and secondary contacts based on email or phone number. If no contact exists, a new primary contact is created.

Request Body:

{
  "email": "[email protected]",
  "phoneNumber": "+1234567890"
}

Response:

  • Case 1: New primary contact created
{
  "contact": {
    "primaryContactId": 23,
    "emails": ["[email protected]"],
    "phoneNumbers": ["+1234567890"],
    "secondaryContactIds": []
  }
}
  • Case 2: Existing contacts found, linked as secondary
{
  "contact": {
    "primaryContactId": 1,
    "emails": ["[email protected]", "[email protected]"],
    "phoneNumbers": ["+1234567890", "+9876543210"],
    "secondaryContactIds": [2, 3]
  }
}
  • Case 3: Existing primary contact converted to secondary
{
  "contact": {
    "primaryContactId": 1,
    "emails": ["[email protected]", "[email protected]"],
    "phoneNumbers": ["+1234567890", "+1122334455"],
    "secondaryContactIds": [2, 3, 4]
  }
}

Possible Errors:

Status Code Error Message
400 {"error": "At least one of email or phoneNumber is required."}

Swagger & ReDoc Documentation:

Access Admin Panel

Username: admin Password: admin123

About

Bitespeed Backend Task: Identity Reconciliation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published