Skip to content

Ads

All endpoints use the base URL /v1. Authenticated endpoints require a valid Bearer token in the Authorization header.


GET /v1/ads

Returns all ad campaigns owned by the authenticated user.

Authentication: Required

Response 200 OK:

{
"ads": [
{
"id": "uuid",
"title": "Summer Sale Campaign",
"content": "Check out our summer collection!",
"budget": 500,
"price_per_view": 0.05,
"spent_budget": 120.50,
"views_count": 2410,
"status": "active",
"media_url": "https://cdn.example.com/ads/summer-sale.jpg",
"target_url": "https://example.com/summer",
"created_at": "2025-06-01T09:00:00.000Z",
"updated_at": "2025-06-10T14:00:00.000Z"
}
]
}

Errors:

StatusDescription
401 UnauthorizedMissing or invalid Bearer token.

POST /v1/ads

Creates a new ad campaign. The ad is created with status set to draft, spent_budget set to 0, and views_count set to 0.

Authentication: Required

Request Body:

FieldTypeRequiredDescription
titlestringYesAd campaign title.
contentstringYesAd copy / description.
budgetnumberYesTotal budget for the campaign.
price_per_viewnumberYesCost deducted per impression.
media_urlstringNoURL to the ad creative (image or video).
target_urlstringNoURL the ad links to when clicked.

Request Example:

{
"title": "Summer Sale Campaign",
"content": "Check out our summer collection with 50% off!",
"budget": 500,
"price_per_view": 0.05,
"media_url": "https://cdn.example.com/ads/summer-sale.jpg",
"target_url": "https://example.com/summer"
}

Response 201 Created:

{
"ad": {
"id": "uuid",
"user_id": "uuid",
"title": "Summer Sale Campaign",
"content": "Check out our summer collection with 50% off!",
"budget": 500,
"price_per_view": 0.05,
"spent_budget": 0,
"views_count": 0,
"status": "draft",
"media_url": "https://cdn.example.com/ads/summer-sale.jpg",
"target_url": "https://example.com/summer",
"created_at": "2025-06-12T08:00:00.000Z"
}
}

Errors:

StatusDescription
400 Bad RequestMissing required fields (title, content, budget, or price_per_view).
401 UnauthorizedMissing or invalid Bearer token.

GET /v1/ads/serve

Returns a random active ad that still has remaining budget (spent_budget < budget). Used to display ads to users. No authentication required.

Authentication: None (public)

Response 200 OK (ad available):

{
"ad": {
"id": "uuid",
"title": "Summer Sale Campaign",
"content": "Check out our summer collection with 50% off!",
"media_url": "https://cdn.example.com/ads/summer-sale.jpg",
"target_url": "https://example.com/summer"
}
}

Response 200 OK (no ads available):

{
"ad": null
}

PATCH /v1/ads/{id}

Updates an ad campaign. Only the ad owner can update their own ads.

Authentication: Required (owner only)

Path Parameters:

ParameterTypeRequiredDescription
iduuidYesThe ad’s unique ID.

Request Body:

Any ad fields can be updated:

FieldTypeRequiredDescription
titlestringNoUpdated ad title.
contentstringNoUpdated ad copy.
budgetnumberNoUpdated total budget.
price_per_viewnumberNoUpdated cost per impression.
media_urlstringNoUpdated media URL.
target_urlstringNoUpdated target URL.

Request Example:

{
"title": "Summer Sale Campaign - Extended!",
"budget": 750
}

Response 200 OK:

{
"ad": {
"id": "uuid",
"title": "Summer Sale Campaign - Extended!",
"budget": 750,
"updated_at": "2025-06-15T10:00:00.000Z"
}
}

Errors:

StatusDescription
401 UnauthorizedMissing or invalid Bearer token.
403 ForbiddenAuthenticated user is not the owner of this ad.
404 Not FoundNo ad exists with the given ID.

DELETE /v1/ads/{id}

Deletes an ad campaign. Only the ad owner can delete their own ads.

Authentication: Required (owner only)

Path Parameters:

ParameterTypeRequiredDescription
iduuidYesThe ad’s unique ID.

Response 200 OK:

{
"message": "Ad deleted"
}

Errors:

StatusDescription
401 UnauthorizedMissing or invalid Bearer token.
403 ForbiddenAuthenticated user is not the owner of this ad.
404 Not FoundNo ad exists with the given ID.

POST /v1/ads/{id}/impression

Records a single ad impression. Increments views_count by 1 and adds price_per_view to spent_budget. If spent_budget exceeds or equals budget after the increment, the ad status is automatically set to paused.

Authentication: None (public)

Path Parameters:

ParameterTypeRequiredDescription
iduuidYesThe ad’s unique ID.

Response 200 OK:

{
"message": "Impression recorded"
}

Errors:

StatusDescription
404 Not FoundNo ad exists with the given ID.

POST /v1/reports

Submits a report against a piece of content or a user. Reports are reviewed by administrators via the Admin Reports endpoints.

Authentication: Required

Request Body:

FieldTypeRequiredDescription
reportable_iduuidYesID of the item being reported.
reportable_typestringYesType of the reported item. One of: post, user, product, comment.
reasonstringYesReason for the report.
descriptionstringNoAdditional details about the report.

Request Example:

{
"reportable_id": "post-uuid",
"reportable_type": "post",
"reason": "Spam content",
"description": "This post contains repeated spam links and irrelevant advertising."
}

Response 201 Created:

{
"report": {
"id": "uuid",
"reporter_id": "uuid",
"reportable_id": "post-uuid",
"reportable_type": "post",
"reason": "Spam content",
"description": "This post contains repeated spam links and irrelevant advertising.",
"status": "pending",
"created_at": "2025-06-12T09:00:00.000Z"
}
}

Errors:

StatusDescription
400 Bad RequestMissing required fields or invalid reportable_type. Must be one of: post, user, product, comment.
401 UnauthorizedMissing or invalid Bearer token.