Skip to main content

Overview

The Publicidades (Advertisements) endpoint allows you to upload and manage advertisement media files associated with specific cities and countries. This endpoint handles file uploads for advertising materials that will be displayed as part of campaigns.

Base URL

/api/publicidades/

Endpoints

List All Advertisements

Retrieve a list of all advertisement media files. Response
id_publicidad
integer
Unique identifier for the advertisement (auto-generated)
fecha_creacion
date
Date when the advertisement was created (format: YYYY-MM-DD)
estado
integer
Advertisement status (0: inactive, 1: active)
imagen_publicitaria
file
The advertisement media file (image, video, or other supported format). Uploaded files are stored in the ads/ directory.
id_ciudad
integer
Foreign key to the city where this advertisement is targeted
id_pais
integer
Foreign key to the country where this advertisement is targeted
fecha_modificacion
date
Date when the advertisement was last modified (format: YYYY-MM-DD)

Create an Advertisement

Upload a new advertisement media file. Request Body This endpoint requires multipart/form-data encoding for file uploads.
fecha_creacion
date
required
Creation date (YYYY-MM-DD)
estado
integer
required
Advertisement status (0: inactive, 1: active)
imagen_publicitaria
file
required
The advertisement media file to upload. Supported formats depend on server configuration. Files are uploaded to the ads/ directory.
id_ciudad
integer
required
ID of the target city
id_pais
integer
required
ID of the target country
fecha_modificacion
date
required
Modification date (YYYY-MM-DD)

Retrieve an Advertisement

Retrieve details of a specific advertisement by ID, including the file URL.

Update an Advertisement

Update all fields of a specific advertisement, including replacing the media file. Request Body Use multipart/form-data encoding when updating the file. Partially update specific fields of an advertisement. You can update metadata without replacing the file.

Delete an Advertisement

Delete a specific advertisement by ID. This also removes the associated media file from storage.

File Upload

When uploading advertisement files:
  1. Use multipart/form-data encoding
  2. Include the file in the imagen_publicitaria field
  3. Files are automatically stored in the ads/ directory
  4. The response includes the file URL path

Example Usage

Creating an Advertisement (JSON representation)

{
  "fecha_creacion": "2024-05-15",
  "estado": 1,
  "imagen_publicitaria": "ads/campaign_banner_2024.png",
  "id_ciudad": 1,
  "id_pais": 1,
  "fecha_modificacion": "2024-05-15"
}

Using cURL to Upload a File

curl -X POST http://your-api-url/api/publicidades/ \
  -F "fecha_creacion=2024-05-15" \
  -F "estado=1" \
  -F "imagen_publicitaria=@/path/to/your/ad_image.png" \
  -F "id_ciudad=1" \
  -F "id_pais=1" \
  -F "fecha_modificacion=2024-05-15" \
  -H "Authorization: Bearer YOUR_TOKEN"

Using JavaScript with FormData

const formData = new FormData();
formData.append('fecha_creacion', '2024-05-15');
formData.append('estado', 1);
formData.append('imagen_publicitaria', fileInput.files[0]);
formData.append('id_ciudad', 1);
formData.append('id_pais', 1);
formData.append('fecha_modificacion', '2024-05-15');

fetch('http://your-api-url/api/publicidades/', {
  method: 'POST',
  body: formData,
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN'
  }
})
.then(response => response.json())
.then(data => console.log(data));

Notes

  • The imagen_publicitaria field accepts file uploads using Django’s FileField
  • Files are stored in the ads/ directory relative to the media root
  • When retrieving advertisements, the file URL will be provided in the response
  • File type validation depends on server configuration
  • Consider implementing file size limits for production use
  • The endpoint returns the file path relative to the media URL

Build docs developers (and LLMs) love