Automation

Why I Prefer APIs Over Browser Automation

Browser automation is tempting because it copies what a person does. APIs are a better base because they give you a contract, structured data and failures you can actually see.

By Published 7 min read

3D render of a browser window with a cursor and warning icon sending frayed wires into a plug hub, which feeds four list cards and a dashboard with a checkmark and charts, all in glowing blue.

There are two broad ways to get software to do a job for you on someone else's platform. You can use the platform's API, the official way for one system to talk to another. Or you can use browser automation: a script that opens a website, finds the right buttons and fields, and clicks and types its way through the task as if it were a person.

Both can work. Browser automation is often the faster way to get something running, because it copies a process you already understand. You can watch it happen, step by step. But when I'm deciding how to build anything that needs to keep running, my default is the API. Here's why, and where I think that rule should bend.

What the difference actually is

An API is a published interface. The platform says, in effect: send a request in this format and you'll get a response in that format. The data comes back structured, with named fields, rather than as a page designed for human eyes. Access is usually controlled by keys or tokens that can be limited to specific permissions.

Browser automation works at the level of the user interface. The script loads pages, waits for elements to appear, finds them by their position or their code identifiers, and interacts with them. It sees what a person sees, and it depends on the page looking and behaving the way it did when the script was written.

That one difference - interface for machines versus interface for people - drives almost everything else.

Why APIs are more dependable

The main reason is that an API is a contract. The platform has made a public promise about how it behaves, and changing that promise has costs for them. Good APIs are versioned, changes are announced in advance, and old versions are usually kept running for a while so people have time to update. That doesn't make APIs permanent, but it does make change predictable.

The data is also cleaner. When you ask an API for a list of orders, posts or products, you get exactly that, in a consistent shape. You don't have to scrape text out of a page, deal with formatting quirks or guess which bit of a table is the price. Less parsing means fewer places for things to go wrong.

And APIs tend to be quicker and lighter. A request and a response is far less work than loading a full web page with its scripts, images and tracking, then waiting for it to settle before anything can be clicked. For anything that runs often or handles a lot of items, that adds up.

Browser automation breaks for reasons that have nothing to do with you

A website's interface is built for people, and it changes whenever the people running it decide it should. A redesign, a renamed button, a new step in a form, a moved menu - none of these are announced to anyone scripting against the page, because nobody promised they wouldn't happen.

There are also plenty of smaller, more irritating causes of failure:

  • A cookie banner or pop-up that appears and covers the button the script needs.
  • A page that loads more slowly than usual, so the script tries to click something that isn't there yet.
  • Different versions of a page being shown to different visitors while the site tests a change.
  • A login that suddenly asks for a verification code or a "are you human?" check.
  • A session that expires halfway through a run.

Each of these can be handled, but each one needs handling. Over time, a browser script tends to collect workarounds, and every workaround is another thing to maintain. In my view, that's the real cost of browser automation: not building it, but keeping it alive.

Failures you can see versus failures you can't

This is the point that matters most to me. When an API call fails, it usually tells you. You get an error code and often a message explaining what went wrong: bad credentials, missing field, too many requests. You can log it, alert on it and retry it sensibly.

Browser automation is much more likely to fail quietly. If a button moves and a different element ends up in its place, the script may click the wrong thing and carry on as if all is well. If a page changes its layout, a scraper may pull the wrong number from the wrong cell and pass it along without complaint. The task "ran", but the result is wrong, and nobody finds out until the damage shows up somewhere else.

I've written before about why automation isn't finished when the task runs. Checking outcomes, not just whether a job completed, matters for any automated process. It matters most for browser automation, because that's where a "successful" run is least likely to mean a correct one.

Permissions, terms and being a reasonable guest

There's a less technical side to this too. Many platforms' terms of service restrict automated access through their website, while explicitly allowing it through their API. Building a process on something the platform has said it doesn't want you to do is a fragile position, whether or not anyone enforces it today.

APIs also handle access more safely. A token can usually be limited to the specific actions a process needs, and revoked without changing anyone's password. Browser automation often needs a real username and password stored somewhere, with all the access that person has. If that's ever exposed, the damage isn't limited to one task.

And APIs come with rate limits that tell you how hard you can push. That's helpful rather than restrictive: it gives you a clear line to stay behind, instead of guessing how many page loads will get you blocked.

When browser automation is the right tool

None of this means browser automation is wrong. There are situations where it's the sensible choice, or the only one:

  • There's no API. Plenty of older systems, supplier portals and niche tools simply don't offer one, or don't expose the bit you need.
  • You're testing your own website. Checking that pages load, forms submit and journeys work is exactly what browser automation is for, and here the interface is the thing you want to test.
  • It's a one-off job. If a task needs doing once and then never again, the maintenance cost doesn't apply.
  • You need to see what a person sees. Checking how a page renders, capturing screenshots or confirming that something visible is actually visible all need a browser.

In those cases I'd still build it defensively: explicit waits rather than fixed delays, checks that confirm each step actually did what it should, screenshots on failure, and alerts when something looks off. The aim is to turn quiet failures into loud ones.

How I'd decide

When I'm looking at a task that needs automating, the questions I'd go through are roughly these, in order:

  1. Is there an official API that covers what's needed? If so, use it.
  2. Is there a webhook, export or feed? Many platforms can push data out, or produce a file on a schedule, which is often simpler than either option.
  3. Does an existing integration tool already connect to it? Someone else may have done the hard work and will maintain it.
  4. Only then, browser automation - built with checks, logging and alerts from the start, and treated as something that will need looking after.

It's also worth thinking about where the data ends up. A process that pulls clean, structured data through an API is much easier to feed into a simple system - a spreadsheet, a database, a publishing workflow - and that's often where the real value is. I've covered one version of that in building a content engine around Google Sheets.

The underlying principle

Automation is only useful if you can trust it without watching it. APIs make that trust easier to earn, because they're designed for machines, they change predictably and they tell you when something goes wrong. Browser automation can do things APIs can't, but it asks for more attention in return.

So my preference isn't a rule against browsers. It's a preference for building on the most stable thing available, and saving the fragile options for when nothing better exists. If you're working out how to connect the systems behind your content and publishing, that's the kind of thinking I bring to content, digital publishing and automation work.

Automation

Why Automation Isn't Finished When the Task Runs

The first successful run is where most people stop. In my view it's where the real work on an automation begins: knowing when it fails, checking what it produces and keeping it alive as things change.

· 7 min read