Use the Piwik API to query the country origin of an IP

I have a web application and I would like to block traffic from certain countries.

Is this possible to do with my Piwik installation using an API call as I keep Piwik fairly up to date with recent IP db details?

1 - AJAX a request to a PHP script on the PIWIK server with the relavent IP address
2 - Have PIWIK return 1 or 0 depending on country of origin.
3 - Load or do not load the login interface to the web application

Yes it is possible! You can use the API call ‘UserCountry.getLocationFromIP’ as explained in How to - Analytics Platform - Matomo