You are a human. This makes you rather slow and dim witted. Unlike computers, which are fast and smart.
Imagine a website whose only functionality is to give you a random number. Because you are squishy, the website has to give you a User Interface (UI). This consists of a button. Once you press the button, the website displays your number.
Now imagine you are a computer. You have no need for silly buttons. Instead, the website can give you an Application Programming Interface (API). When you send a message to an endpoint (computer language for button), that endpoint messages you back with your number. Much more efficient than buttons.
We can make the API do everything that we can make the UI do. For example, if you want to specify a range of numbers, the human would enter these in input fields. The computer would give them to the endpoint. If we want to add a button that gives you a random color, we can add an endpoint that gives you a random color.
APIs are better than UIs in every way except one: they are hard to use for humans. This is why we make UIs for tasks that have to be done by humans, and APIs for tasks that can be done exclusively by computers.