Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Priyanshu471/ad-management/llms.txt

Use this file to discover all available pages before exploring further.

The /api/campaign route is the core of the Ad Management System and supports four HTTP methods covering the complete lifecycle of an ad campaign. GET retrieves every campaign stored in MongoDB, POST creates a new campaign and associates it with an existing user, PATCH updates a campaign’s fields by matching on its current title, and DELETE permanently removes a campaign by its MongoDB _id. All four methods share the same endpoint URL and communicate exclusively over JSON.

GET /api/campaign

Returns every campaign document stored in the MongoDB campaigns collection. No request body is required.

Response 200

{
  "campaigns": [
    {
      "_id": "65f1a2b3c4d5e6f7a8b9c0d2",
      "title": "Just Do It",
      "description": "Campaign description",
      "objective": "Brand Awareness",
      "status": "Active",
      "budget": "10000",
      "duration": "10 days",
      "user": "65f1a2b3c4d5e6f7a8b9c0d1",
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    }
  ]
}

cURL Example

curl http://localhost:3000/api/campaign

POST /api/campaign

Creates a new campaign document in MongoDB and embeds the full user object retrieved by userId. The new campaign is returned in the response body upon success.

Request Body

title
string
required
The display title of the campaign.
description
string
required
A short description of the campaign’s purpose or messaging.
objective
string
required
The marketing objective for the campaign. Must be one of the nine supported values — see Campaign Objectives.
budget
string
required
The total allocated budget for the campaign, represented as a string (e.g. "50000").
duration
string
required
How long the campaign runs (e.g. "30 days").
userId
string
required
The MongoDB _id of the user creating the campaign. Used to look up and embed the user document.

Request Example

{
  "title": "Summer Sale 2024",
  "description": "Boost summer product sales",
  "objective": "Conversions",
  "budget": "50000",
  "duration": "30 days",
  "userId": "65f1a2b3c4d5e6f7a8b9c0d1"
}

Response 200

{
  "newCampaign": {
    "_id": "65f1a2b3c4d5e6f7a8b9c0d3",
    "title": "Summer Sale 2024",
    "description": "Boost summer product sales",
    "objective": "Conversions",
    "status": "Active",
    "budget": "50000",
    "duration": "30 days",
    "user": "65f1a2b3c4d5e6f7a8b9c0d1",
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-15T10:30:00.000Z"
  }
}

Error Response

StatusBodyCause
500Raw error message stringUnexpected server or MongoDB error

cURL Example

curl -X POST http://localhost:3000/api/campaign \
  -H "Content-Type: application/json" \
  -d '{"title":"Summer Sale 2024","description":"Boost sales","objective":"Conversions","budget":"50000","duration":"30 days","userId":"65f1a2b3c4d5e6f7a8b9c0d1"}'

PATCH /api/campaign

Updates one or more fields on an existing campaign. The target document is located by matching prevTitle against the campaign’s current title field in MongoDB using Campaign.findOneAndUpdate({ title: prevTitle }, ...). Any combination of the remaining fields can be provided to update only those values.

Request Body

prevTitle
string
required
The current title of the campaign. Used as the lookup key to find the document to update. This field is always required, even if you are not changing the title.
title
string
The new title to set on the campaign.
description
string
The updated campaign description.
budget
string
The updated budget value.
duration
string
The updated campaign duration.
status
string
The updated campaign status.

Request Example

{
  "prevTitle": "Summer Sale 2024",
  "title": "Summer Sale Updated",
  "status": "Active"
}

Response 200

{ "message": "Campaign updated " }

Error Response

StatusBodyCause
500Raw error message stringUnexpected server or MongoDB error

cURL Example

curl -X PATCH http://localhost:3000/api/campaign \
  -H "Content-Type: application/json" \
  -d '{"prevTitle":"Summer Sale 2024","title":"Summer Sale Updated","status":"Active"}'
The campaign is located by prevTitle — if no document has a title matching prevTitle, the update silently does nothing. Always include prevTitle to ensure the correct campaign is targeted.

DELETE /api/campaign

Permanently removes a campaign from MongoDB by its _id. This operation cannot be undone.

Request Body

id
string
required
The MongoDB _id of the campaign to delete.

Request Example

{ "id": "65f1a2b3c4d5e6f7a8b9c0d3" }

Response 200

{ "message": "Campaign deleted permanently" }

Error Response

StatusBodyCause
500Raw error message stringUnexpected server or MongoDB error

cURL Example

curl -X DELETE http://localhost:3000/api/campaign \
  -H "Content-Type: application/json" \
  -d '{"id":"65f1a2b3c4d5e6f7a8b9c0d3"}'
Deletion is permanent — there is no soft-delete or trash mechanism. Verify the campaign _id before calling this endpoint. Consider adding a confirmation step in your UI before dispatching the request.

Build docs developers (and LLMs) love