<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alex</title>
    <description>The latest articles on DEV Community by Alex (@content_ai).</description>
    <link>https://dev.to/content_ai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4032911%2F62e877c8-e135-4b60-8a2c-f474328672e5.png</url>
      <title>DEV Community: Alex</title>
      <link>https://dev.to/content_ai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/content_ai"/>
    <language>en</language>
    <item>
      <title>API-first or browser automation? Lessons from shipping content autoposting</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Fri, 17 Jul 2026 01:13:51 +0000</pubDate>
      <link>https://dev.to/content_ai/api-first-or-browser-automation-lessons-from-shipping-content-autoposting-55pl</link>
      <guid>https://dev.to/content_ai/api-first-or-browser-automation-lessons-from-shipping-content-autoposting-55pl</guid>
      <description>&lt;p&gt;We built a pipeline that generates content and ships it to several platforms. Generation turned out to be the easy half. &lt;strong&gt;Publishing&lt;/strong&gt; is where the real engineering was — and where I burned the most hours. Here is what I'd tell my past self.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rule I landed on: API when it exists, browser only when it doesn't
&lt;/h2&gt;

&lt;p&gt;Not every platform exposes a publishing API. The tempting shortcut is to drive a headless browser everywhere. Don't. Two reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Some platforms explicitly forbid it.&lt;/strong&gt; X's automation rules are blunt: &lt;em&gt;"Non-API-based forms of automation, such as scripting the X website, may result in permanent suspension."&lt;/em&gt; If an API exists, scripting the site is not a clever workaround — it's a ban waiting to happen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser automation is inherently fragile.&lt;/strong&gt; It breaks the moment someone renames a CSS class.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So the rule: &lt;strong&gt;API adapter by default. Browser automation only where no API exists, and only for actions the account owner is allowed to perform.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What platforms actually allow
&lt;/h2&gt;

&lt;p&gt;I checked the primary docs (not blog posts) for each. Official publishing APIs where automation of your own account is permitted:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Platform&lt;/th&gt;
&lt;th&gt;Auth&lt;/th&gt;
&lt;th&gt;Content&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Telegram (Bot API)&lt;/td&gt;
&lt;td&gt;static bot token&lt;/td&gt;
&lt;td&gt;short / channel posts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bluesky (AT Protocol)&lt;/td&gt;
&lt;td&gt;app password → session JWT&lt;/td&gt;
&lt;td&gt;short&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mastodon&lt;/td&gt;
&lt;td&gt;OAuth token&lt;/td&gt;
&lt;td&gt;short&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DEV.to / Forem&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;api-key&lt;/code&gt; header&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;long-form Markdown&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ghost&lt;/td&gt;
&lt;td&gt;Admin API key → JWT&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;long-form&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LinkedIn&lt;/td&gt;
&lt;td&gt;OAuth (&lt;code&gt;w_member_social&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;short/medium&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The &lt;strong&gt;universal enforcement rule&lt;/strong&gt; is remarkably consistent across all of them:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Posting &lt;em&gt;your&lt;/em&gt; content to &lt;em&gt;your&lt;/em&gt; account: fine.&lt;br&gt;
Identical content across multiple accounts, bulk/aggressive actions, unsolicited notification spam: banned.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vary content per platform, respect rate limits, don't automate &lt;em&gt;interactions&lt;/em&gt;. That's the whole game.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser automation gotchas (the expensive ones)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. "Am I logged in?" — don't assert on text anonymous users also see
&lt;/h3&gt;

&lt;p&gt;My first check looked for words like &lt;em&gt;"My feed"&lt;/em&gt; and &lt;em&gt;"Write"&lt;/em&gt;. Both are visible to logged-out visitors. The script cheerfully reported success while completely unauthenticated.&lt;/p&gt;

&lt;p&gt;Assert on the &lt;strong&gt;absence&lt;/strong&gt; of the thing that shouldn't be there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loginBtn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sign in&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;loginBtn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isVisible&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Native &lt;code&gt;confirm()&lt;/code&gt; dialogs are not in the DOM
&lt;/h3&gt;

&lt;p&gt;The publish button fired a native &lt;code&gt;confirm()&lt;/code&gt;. I spent an embarrassing amount of time hunting for a second DOM button that never existed. Playwright auto-dismisses native dialogs unless you handle them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dialog&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Rich editors: the body block may not exist yet
&lt;/h3&gt;

&lt;p&gt;The empty editor had &lt;strong&gt;only&lt;/strong&gt; a title field. The body block is created when you press Enter from the title. My naive "click the editor and type" appended the first paragraph &lt;em&gt;into the title&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;Title: My Article HeadlineThe first paragraph of my article...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fix is to type like a human:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;titleField&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keyboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keyboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;press&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Enter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;        &lt;span class="c1"&gt;// &amp;lt;- this creates the body block&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;paragraphs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keyboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;paragraphs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keyboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;press&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Enter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then &lt;strong&gt;verify by reading it back&lt;/strong&gt;. Don't trust a screenshot that "looked fine":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;titleText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;titleField&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;innerText&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;locator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.editor-text-tool&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;innerText&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That single assertion caught the bug that three screenshots missed.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Sessions expire, quietly
&lt;/h3&gt;

&lt;p&gt;A saved &lt;code&gt;storageState&lt;/code&gt; worked beautifully — for about two to three weeks. Then a run came back &lt;code&gt;auth_required&lt;/code&gt;. Build re-authentication in as a normal automated step, not a manual emergency.&lt;/p&gt;

&lt;h2&gt;
  
  
  API gotchas
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Versioned APIs expire
&lt;/h3&gt;

&lt;p&gt;LinkedIn requires a &lt;code&gt;LinkedIn-Version: YYYYMM&lt;/code&gt; header and keeps roughly the last 12 months active. A hardcoded default that was fine at write-time returns this at run-time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;HTTP 426 — Requested version 20250501 is not active
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Anything with a date baked into it belongs in config, not in a constant.&lt;/strong&gt; Same for token lifetime (60 days for LinkedIn) — treat rotation as a scheduled task, not a surprise.&lt;/p&gt;

&lt;h2&gt;
  
  
  The architecture that held up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One adapter contract per platform:&lt;/strong&gt; &lt;code&gt;validate → prepare → publish → verify → collectResult&lt;/code&gt;. Adding a platform means writing one file, not touching the orchestrator.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secrets in env, never in the database.&lt;/strong&gt; Outward (UI / API / logs) we expose only masked booleans: &lt;code&gt;configured&lt;/code&gt;, &lt;code&gt;publishEnabled&lt;/code&gt;. A token has never once been logged.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Idempotency by request hash:&lt;/strong&gt; &lt;code&gt;sha256(draftId + destinationId + contentHash + mode)&lt;/code&gt;. A prior &lt;code&gt;success&lt;/code&gt; → skip, return the existing URL. A prior &lt;code&gt;unknown&lt;/code&gt; (the network died mid-request, we genuinely don't know if it landed) → &lt;strong&gt;never blind-retry&lt;/strong&gt;; flag &lt;code&gt;needs_manual_review&lt;/code&gt;. Duplicate posts are worse than a missing one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two flags to publish for real:&lt;/strong&gt; &lt;code&gt;dryRun=false&lt;/code&gt; &lt;strong&gt;and&lt;/strong&gt; &lt;code&gt;publishConfirm=true&lt;/code&gt;. Defaults are safe, so an accidental run can only ever produce a preview.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop, don't bypass.&lt;/strong&gt; Captcha, 2FA, an emailed verification code → status &lt;code&gt;waiting_human&lt;/code&gt;. We never solve a challenge. That line is what separates "a robot operating the owner's account" from "a bot pretending to be a human".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;API-first.&lt;/strong&gt; Browser automation is a fallback, not a default — and on some platforms it's a ban.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read the automation policy before writing the adapter.&lt;/strong&gt; It changes what you build, not just whether you're allowed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assert on absence,&lt;/strong&gt; not on presence of a happy-path string.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anything dated (API versions, tokens) goes in config.&lt;/strong&gt; It will expire while you sleep.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make "publish for real" require two deliberate flags.&lt;/strong&gt; Your future self will hit Enter on the wrong terminal eventually.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The unglamorous truth: the model that writes the post is the commodity. The reliability layer around it — idempotency, gating, honest failure states — is the actual product.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>api</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
