For programmatic checking of modern HTML documents, use the API provided by the W3C HTML Checker. To do that, call https://validator.w3.org/nu/ or the URL for another instance of the W3C HTML Checker, and consult the following documentation:
Also available is historical documentation about the obsolete SOAP 1.2 API for the Markup Validator (which you should no longer use).