Skip to main content
The application persists news items to a WordPress instance running at pruebas01.dev.cordoba.gob.ar using the WordPress REST API. Items are stored as a custom post type called noticia with all NewsItem fields stored in Advanced Custom Fields (ACF) meta fields. All API communication is encapsulated in SharedService.

Base URL

https://pruebas01.dev.cordoba.gob.ar/wp-json/wp/v2/noticia

Authentication

Every request uses HTTP Basic Authentication with the WordPress application password feature:
  • Username: ctrolmedios
  • Password: WordPress application password (stored in the Angular environment or service configuration)
The credentials are base64-encoded and sent in the Authorization header on every request.
const headers = new HttpHeaders({
  Authorization: 'Basic ' + btoa('ctrolmedios:YOUR_APP_PASSWORD')
});
The application password is currently hardcoded in SharedService. For any deployment beyond local development, move the credentials to an Angular environment file (environment.ts) that is excluded from the repository, and reference them via environment.appPassword.

Endpoints

GET /wp/v2/noticia — list news items

Fetches persisted news items from WordPress. The application always fetches all available posts by paginating through every page. Query parameters
query.per_page
number
default:"100"
Number of posts to return per page. The application uses 100 (the WordPress maximum) to minimise the number of requests.
query.page
number
default:"1"
Page number to fetch. Incremented automatically by the pagination logic in leerNoticias().
query.nocache
number
A Date.now() timestamp appended to every request URL to prevent the browser from returning a cached response.
Response An array of WordPress post objects. Each object contains an id (the WordPress post ID) and an acf object holding all NewsItem fields.
[
  {
    "id": 42,
    "title": { "rendered": "Inauguraron el nuevo centro de salud en barrio Müller." },
    "acf": {
      "id_": "150324090430",
      "sendDate": "15/3/24",
      "sendTime": "9:04:30 AM",
      "media": "Canal 12",
      "program": "Mediodía",
      "text": "Inauguraron el nuevo centro de salud en barrio Müller.",
      "link": "https://example.com/nota",
      "startTime": "09:00",
      "endTime": "09:30",
      "topics": "Salud",
      "iaResume": "El municipio inauguró...",
      "destacada": false
    }
  }
]
Access fields as item.acf.fieldName. The topic array is not stored; only the semicolon-joined topics string is persisted. Split on ";" to reconstruct the array when reading items back.

POST /wp/v2/noticia — create a news item

Creates a new noticia post in WordPress. Called by guardarNoticias() when copyAll() determines that an item does not yet exist in the saved list. Request body
body.title
string
required
The post title. Set to the value of NewsItem.iaResume.
body.content
string
required
The post content body. Always set to the static string "Contenido enriquecido".
body.status
string
required
WordPress post status. Always "publish".
body.acf
object
required
The full NewsItem object. All fields are written to ACF custom fields on the post.
Example request body
{
  "title": "El municipio inauguró el nuevo centro de salud en barrio Müller.",
  "content": "Contenido enriquecido",
  "status": "publish",
  "acf": {
    "id_": "150324090430",
    "sendDate": "15/3/24",
    "sendTime": "9:04:30 AM",
    "media": "Canal 12",
    "program": "Mediodía",
    "text": "Inauguraron el nuevo centro de salud en barrio Müller.",
    "link": "https://example.com/nota",
    "startTime": "09:00",
    "endTime": "09:30",
    "topics": "Salud",
    "iaResume": "El municipio inauguró el nuevo centro de salud en barrio Müller.",
    "destacada": false
  }
}

POST /wp/v2/noticia/:id — update a news item

Updates an existing noticia post in WordPress. Called by ActualizarNoticias() when copyAll() finds a matching post by id_ in the saved list. Path parameter
path.id
number
required
The WordPress post ID of the existing noticia post. Taken from existingPost.id in the saved items list.
Request body Identical shape to the create endpoint. The acf object is the NewsItem spread with the WordPress post id added:
// Inside copyAll()
ActualizarNoticias({ ...newsItem, id: existingPost.id })
{
  "title": "El municipio inauguró el nuevo centro de salud en barrio Müller.",
  "content": "Contenido enriquecido",
  "status": "publish",
  "acf": {
    "id_": "150324090430",
    "media": "Canal 12"
  }
}

Upsert logic (copyAll())

When an operator dispatches a category from PanelComponent, copyAll() iterates over every item in the current category and applies the following upsert logic:
1

Look up the item

Search DataService.noticiasGuardadas for an existing post whose acf.id_ matches the current newsItem.id_.
2

Update if found

If a matching post is found, call ActualizarNoticias({ ...newsItem, id: existingPost.id }) to overwrite the existing WordPress post.
3

Create if not found

If no matching post exists, call guardarNoticias(newsItem) to create a new post.
// Pseudocode for copyAll() upsert decision
const existing = noticiasGuardadas.find(
  (saved) => saved.acf.id_ === newsItem.id_
);

if (existing) {
  ActualizarNoticias({ ...newsItem, id: existing.id });
} else {
  guardarNoticias(newsItem);
}

SharedService methods

getPalabrasClave()

Fetches the keyword-to-category mapping from a Google Sheets spreadsheet via the Google Visualization API.
  • Returns: Observable<string> — the raw query response from the Sheets Visualization endpoint
  • Called by: Application initialisation to populate DataService.palabrasClaveOriginal and DataService.categorias
  • Async: Yes — wraps an HTTP GET request in an Observable
async getPalabrasClave() {
  const URL = `https://docs.google.com/spreadsheets/d/${this.sheetPalabrasClave}/gviz/tq?tqx=out:json`;
  return this.http.get(URL, { responseType: 'text' });
}
The Google Visualization API returns a JSONP-like response with a google.visualization.Query.setResponse(...) wrapper. Strip this wrapper before parsing the JSON payload.

guardarNoticias(data)

POSTs a new news item to WordPress.
  • Parameters: data — a NewsItem object
  • Returns: void
  • Side effects: Creates a new noticia post. On success, does not update local state directly; call leerNoticias() afterwards to refresh DataService.noticiasGuardadas.
guardarNoticias(data: any): void {
  const credentials = btoa('ctrolmedios:APP_PASSWORD');
  fetch('https://pruebas01.dev.cordoba.gob.ar/wp-json/wp/v2/noticia', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Basic ${credentials}`,
    },
    body: JSON.stringify({
      title: data.iaResume,
      content: 'Contenido enriquecido',
      status: 'publish',
      acf: { ...data },
    }),
  });
}

ActualizarNoticias(data)

POSTs an update to an existing WordPress news item.
  • Parameters: data — a NewsItem extended with an id property (the WordPress post ID)
  • Returns: void
  • Side effects: Overwrites the existing noticia post at /wp/v2/noticia/:id.
ActualizarNoticias(data: any): void {
  const id = data.id;
  const credentials = btoa('ctrolmedios:APP_PASSWORD');
  fetch('https://pruebas01.dev.cordoba.gob.ar/wp-json/wp/v2/noticia/' + id, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Basic ${credentials}`,
    },
    body: JSON.stringify({
      title: data.iaResume,
      content: 'Contenido enriquecido',
      status: 'publish',
      acf: { ...data },
    }),
  });
}

leerNoticias()

Fetches all persisted news items from WordPress, paginating through every available page.
  • Returns: Observable<any[]> — emits a single array containing every post across all pages once pagination is complete
  • Pagination: Fetches page 1, checks if the result length equals per_page (100). If so, increments the page counter and fetches again, concatenating results. Stops when a page returns fewer than 100 items.
leerNoticias(): Observable<any[]> {
  let allNews: any[] = [];
  let page = 1;
  const perPage = 100;

  const getPage = (): Promise<any> => {
    return this.http.get(
      `https://pruebas01.dev.cordoba.gob.ar/wp-json/wp/v2/noticia` +
      `?per_page=${perPage}&page=${page}&nocache=${Date.now()}`,
      { responseType: 'json' }
    ).toPromise().then((news: any) => {
      allNews = allNews.concat(news);
      if (news.length === perPage) {
        page++;
        return getPage();
      } else {
        return allNews;
      }
    });
  };

  return from(getPage());
}
leerNoticias() converts the paginated Promise chain into an RxJS Observable using from(). Subscribe to the returned Observable to receive the full result array. The nocache timestamp query parameter ensures WordPress does not serve a cached response.

Build docs developers (and LLMs) love