To get API access to Wikipedia, you use the MediaWiki API. Wikipedia has quite an extensive documentation of this API, but one thing I can't seem to find is how to exclude disambiguation pages from the search results. I use JavaScript to fetch using this URL:
https://nl.wikipedia.org/w/api.php?format=json&action=query&prop=extracts|pageimages|categories|info|pageprops&ppprop=disambiguation&exintro&exsentences=2&pithumbsize=500&redirects=1&inprop=url&cllimit=1&origin=*&titles=${query}
I found that using prop=pageprops and ppprop=disambiguation makes it possible to identify a disambiguous page. When a page is disambiguous, I would ideally have my function identify the first page that is linked in this disambiguation page and run the query again for that pageid. Or is there maybe an easier way to just return the first non-disambiguous article?