When I call a REST API I get JSON response with unencoded chars

While working on a NodeJS project I needed to make a REST call to a Mexican API to get profesional licensing information. Everything works fine except for the fact that all special chars such as ñ, á, ó etc. appear as �.

This is my code:

const express = require('express')
const fetch = require('node-fetch')
const cors = require('cors')
// const querystring = require('querystring')
// const qs = require('qs')

const app = express()
const license = '0987655' // This is hardcoded for debugging 

app.use(cors({credentials: true}))
  
  const responseAPI = async (license) => {
  const query = fetch("https://cedulaprofesional.sep.gob.mx/cedula/buscaCedulaJson.action", {
    credentials: "include",
    headers: {
      "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0",
      Accept: "*/*",
      "Accept-Language": "es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3",
      "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
      "X-Requested-With": "XMLHttpRequest",
      "Sec-Fetch-Dest": "empty",
      "Sec-Fetch-Mode": "cors",
      "Sec-Fetch-Site": "same-origin",
      "Sec-GPC": "1",
    },
    referrer: "https://cedulaprofesional.sep.gob.mx/cedula/presidencia/indexAvanzada.action",
    body: `json=%7B%22maxResult%22%3A%221000%22%2C%22nombre%22%3A%22%22%2C%22paterno%22%3A%22%22%2C%22materno%22%3A%22%22%2C%22idCedula%22%3A%22${license}%22%7D`,
    method: "POST",
    mode: "cors",
  });
    // The idea is to return the result but i log it for debugging
    const result = await (await query).json()
    console.log('Result >>', result)
  };
responseAPI(license)

The result is:


Result >> {
  items: [
    {
      anioreg: 1985,
      carArea: null,
      carCons: null,
      carNivel: null,
      carSarea: null,
      curp: null,
      desins: 'UNIVERSIDAD NACIONAL AUT�NOMA DE M�XICO',
      foja: null,
      idCedula: '0987655',
      inscons: 1,
      insedo: 9,
      libro: null,
      materno: 'RAMIREZ',
      maternoM: null,
      nombre: 'AURORA',
      nombreM: null,
      numero: null,
      paterno: 'PARRA',
      paternoM: null,
      sexo: '2',
      tipo: 'C1',
      titulo: 'LICENCIATURA COMO CIRUJANO DENTISTA'
    }
  ],
  filename: null,
  idCedula: null,
  idProfesionista: null,
  sessionId: null,
  theStream: null,
  token: null,
  urlVideo: null
}

The expected output shouls be:

// Omitted output
      desins: 'UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO',

// Omitted output

The thing is that the official site displays everything as it should, but when I use Firefox to copy the fetch call it shows the ‘error’.

I tried:

  • using qs
  • using querystring

So that’s it. I would really appreciate any input