Nationality API returning SQ as nationality

271 Views Asked by At

I'm using 2 apis, being https://api.nationalize.io/?name= to guess someone's nationality from their name, and http://country.io/names.json to convert the two letter country code to a country name. This system works great, but while testing I noticed the name corrine returned SQ as the nationality. The api uses ISO 3166-1 alpha-2, but SQ doesn't represent any country in this system. Another naming system says it represents Albania, but Albania is returned as AL from the api. Please help

Test : https://api.nationalize.io/?name=corrine Albania : https://api.nationalize.io/?name=Alteo

Tried looking for countries with SQ tag, but couldn't find any

1

There are 1 best solutions below

0
salluthdev On

Yes, the SQ is wrong. The right result is SG, not SQ.

So, we can try to create conditional like this:

fetch(`https://api.nationalize.io?name=corrine`)
  .then((res) => res.json())
  .then((data) => {
    const fixedResult = data.country
      ?.map((country) => {
        if (country.country_id === "SQ") {
          return { ...country, country_id: "SG" };
        } else {
          return country;
        }
      })
  console.log(fixedResult)
});

Anyway, you can check my project in the nametionalize.vercel.app. Happy coding!