Debugging Wikipedia API Integration: How Geography Finally Caught Up With Me
- Jan 13
- 3 min read
If you had told my secondary-school self that one day I’d be building a map, I would have laughed. Loudly.
I was an art student—the creative kind—but I still did some science subjects. I even had an A in biology. LOL. So no, I wasn’t dull. I just had very clear opinions about certain subjects.
Geography was one of them.
Anything involving calculations? Latitudes? Longitudes? None of my business. I avoided them like a plague. The only time I ever took mathematics seriously in my life was when my dad promised to buy me a brand-new phone if I passed my O-Level exams in one sitting. Motivation works, by the way—because I didn’t just pass Mathematics in WASSCE (West African Senior School Certificate Examination); I aced it with an A and went on to get a B in Economics.
So no—it wasn’t inability. It was selective interest. :)
Fast-forward almost three decades, and the very thing I dodged all my life came looking for me.
“Build a Map.”
That was it. One sentence. One project brief.
I stared at it for days. Literally three days, rereading the brief over and over because I refused to believe what I was seeing. My school was telling me—telling me—that my final project was to build a MAP.
A map.
Y’all… I didn’t even know what a gazetteer meant.
To show you how uninterested I was in geography, when I relocated to the UK a few years ago, I got lost several times simply because I couldn’t use a map properly. I only started finding my way confidently when Google Maps introduced the Live View feature—or maybe it had always been there and I just needed a better phone to notice it. LOL.
Long story short, my first final project was to develop a gazetteer app—not just any gazetteer, but one I had to own and make feel unique.
After a lot of back-and-forth (and internal resistance), I built it.
And then I met a problem that cost me 72 hours of my life because I was convinced my code was broken.
Spoiler alert: It wasn’t.
The Bug That Nearly Broke Me
Debugging the Wikipedia API
While integrating Wikipedia’s REST API into my gazetteer app, I kept getting “No articles found” errors for some countries—even though the same code worked perfectly for others.
Naturally, I assumed:
my logic was wrong
my API call was broken
or I had somehow ruined everything again :(
After hours of debugging, logging, and second-guessing myself, I finally realised the issue wasn’t my code at all.
It was how Wikipedia expects country names.
What Was Actually Going Wrong
1. Country Names vs ISO Codes
Wikipedia’s summary endpoint does not accept ISO country codes.
So this fails:
AO
GB
NG
But this works:
Angola
United_Kingdom
Nigeria
Sending ISO codes guarantees failed lookups—even though they look perfectly valid.
2. Spaces Must Become Underscores
Wikipedia REST endpoints do not tolerate spaces.
So:
United States
South Africa
Must become:
United_States
South_Africa
Miss this, and you’ll get a 404—even if the article exists.
3. Canonical Titles Are Not Always Obvious
Some countries don’t use their common names as Wikipedia article titles.
For example:
Côte d’Ivoire → Ivory_Coast
This means you must handle edge cases manually if you want reliable results.
4. Cache Will Gaslight You
Old cache files can make it look like your fix didn’t work.
Clear your cache. Always.
5. Logging Saves Lives
Logging the actual fallback URL, HTTP status, and response body was what finally exposed the issue.
Without logs, I would probably still be staring at my screen.
The Fix That Finally Worked
After 72 hours of blaming myself, the solution turned out to be painfully simple.
I introduced a manual mapping for countries whose Wikipedia titles don’t match their common names.
Here’s the exact PHP code that fixed everything:

Once I added this mapping, the mysterious “No articles found” errors disappeared instantly.
No broken API. No bad logic. Just Geography finally catching up with me. :)
Final Takeaway
So if you ever need to use the Wikipedia API in any of your apps—or in a gazetteer (which you honestly can’t avoid if you train in my school)—keep this in mind.
Wikipedia is strict
Canonical titles matter
ISO codes won’t save you
Caching can lie to you
And domain knowledge you avoided years ago may come back… loudly
The latitudes and longitudes I ignored in secondary school eventually caught up with me—just wearing a developer badge this time. :)





Comments