<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>wordpress api automation Archives - WP-CLI Mastery</title>
	<atom:link href="https://wpclimastery.com/blog/tag/wordpress-api-automation/feed/" rel="self" type="application/rss+xml" />
	<link>https://wpclimastery.com/blog/tag/wordpress-api-automation/</link>
	<description>Automate WordPress Like a DevOps Pro.</description>
	<lastBuildDate>Mon, 24 Nov 2025 11:16:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wpclimastery.com/wp-content/uploads/2025/11/cropped-favicon-32x32.webp</url>
	<title>wordpress api automation Archives - WP-CLI Mastery</title>
	<link>https://wpclimastery.com/blog/tag/wordpress-api-automation/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WordPress REST API + WP-CLI: Complete Automation Integration Guide</title>
		<link>https://wpclimastery.com/blog/wordpress-rest-api-wp-cli-complete-automation-integration-guide/</link>
		
		<dc:creator><![CDATA[Krasen]]></dc:creator>
		<pubDate>Sat, 20 Dec 2025 09:00:00 +0000</pubDate>
				<category><![CDATA[API Integration Tutorials]]></category>
		<category><![CDATA[curl wordpress api]]></category>
		<category><![CDATA[rest api wpcli]]></category>
		<category><![CDATA[wordpress api automation]]></category>
		<category><![CDATA[wordpress rest api]]></category>
		<category><![CDATA[wp-cli rest api]]></category>
		<guid isPermaLink="false">https://wpclimastery.com/?p=139</guid>

					<description><![CDATA[<p>WordPress REST API lets external applications interact with your site, but testing endpoints manually through browsers or Postman wastes time. Authenticating requests, managing tokens, and debugging API responses becomes tedious...</p>
<p>The post <a href="https://wpclimastery.com/blog/wordpress-rest-api-wp-cli-complete-automation-integration-guide/">WordPress REST API + WP-CLI: Complete Automation Integration Guide</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>WordPress REST API lets external applications interact with your site, but testing endpoints manually through browsers or Postman wastes time. Authenticating requests, managing tokens, and debugging API responses becomes tedious without proper tooling.</p>



<p>WP-CLI combined with curl and REST API gives you complete WordPress automation—create posts from external systems, sync content between sites, integrate with third-party services, and build powerful API-driven workflows from your terminal.</p>



<p>In this guide, you’ll learn to leverage WordPress REST API with WP-CLI for automated content management, headless WordPress setups, and integration workflows used by modern WordPress applications.</p>



<h3 class="wp-block-heading" id="why-combine">Why Combine WordPress REST API with WP-CLI?</h3>



<p><a href="https://developer.wordpress.org/rest-api/">WordPress REST API</a> provides HTTP endpoints for WordPress data, while WP-CLI offers direct database access—together they’re unstoppable.</p>



<h4 class="wp-block-heading" id="wordpress-rest-api-limitations-alone">WordPress REST API Limitations Alone</h4>



<p><strong>Authentication complexity</strong>: Setting up OAuth or application passwords is tedious.</p>



<p><strong>Rate limiting</strong>: API requests can be throttled during bulk operations.</p>



<p><strong>Debugging difficulty</strong>: Hard to see what’s happening inside WordPress during API calls.</p>



<p><strong>No direct database</strong>: Can’t bypass API to directly manipulate data when needed.</p>



<p><strong>Testing challenges</strong>: Need external tools to test endpoints during development.</p>



<h4 class="wp-block-heading" id="combined-wp-cli-rest-api-advantages">Combined WP-CLI + REST API Advantages</h4>



<p><strong>Fast prototyping</strong>: Use WP-CLI to create test data for API development.</p>



<p><strong>Hybrid workflows</strong>: Use API for external integration, WP-CLI for direct operations.</p>



<p><strong>Better debugging</strong>: Check database state with WP-CLI while testing API calls.</p>



<p><strong>Authentication bypass</strong>: Use WP-CLI for admin tasks, API for user-facing features.</p>



<p><strong>Complete automation</strong>: Build complex workflows combining both tools.</p>



<p>According to <a href="https://developer.wordpress.org/">WordPress API usage statistics</a>, REST API adoption has grown 300% since 2020, making API skills essential.</p>



<h3 class="wp-block-heading" id="api-basics">WordPress REST API Basics</h3>



<p>Understand WordPress REST API fundamentals before automation.</p>



<h4 class="wp-block-heading" id="test-api-endpoints-with-curl">Test API Endpoints with curl</h4>



<div class="sourceCode" id="cb1">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="co"># Get site information</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a><span class="co"># List all posts</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/wp/v2/posts</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a><span class="co"># Get specific post</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/wp/v2/posts/123</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a><span class="co"># List users</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/wp/v2/users</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true"></a></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true"></a><span class="co"># Get categories</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/wp/v2/categories</span></code></pre>
</div>



<h4 class="wp-block-heading" id="pretty-print-json-responses">Pretty Print JSON Responses</h4>



<div class="sourceCode" id="cb2">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="co"># Install jq for JSON formatting</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a><span class="ex">apt-get</span> install jq</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a><span class="co"># Pretty print API response</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a><span class="ex">curl</span> -s https://example.com/wp-json/wp/v2/posts <span class="kw">|</span> <span class="ex">jq</span> <span class="st">'.'</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a><span class="co"># Extract specific fields</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a><span class="ex">curl</span> -s https://example.com/wp-json/wp/v2/posts <span class="kw">|</span> <span class="ex">jq</span> <span class="st">'.[].title.rendered'</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true"></a></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true"></a><span class="co"># Get post count</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true"></a><span class="ex">curl</span> -s https://example.com/wp-json/wp/v2/posts <span class="kw">|</span> <span class="ex">jq</span> <span class="st">'length'</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="verify-rest-api-is-enabled">Verify REST API is Enabled</h4>



<div class="sourceCode" id="cb3">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="co"># Check if REST API responds</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a><span class="ex">curl</span> -I https://example.com/wp-json/</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a><span class="co"># Should return: HTTP/1.1 200 OK</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a><span class="co"># Use WP-CLI to check REST API status</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a><span class="ex">wp</span> rest</span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a><span class="co"># List all available REST routes</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a><span class="ex">wp</span> rest route list</span></code></pre>
</div>



<p>Learn more in the <a href="https://developer.wordpress.org/rest-api/reference/">WordPress REST API handbook</a>.</p>



<h3 class="wp-block-heading" id="authentication">REST API Authentication</h3>



<p>Authenticate API requests for write operations.</p>



<h4 class="wp-block-heading" id="application-passwords-recommended">Application Passwords (Recommended)</h4>



<div class="sourceCode" id="cb4">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="co"># Create application password with WP-CLI</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a><span class="ex">wp</span> user application-password create admin <span class="st">"API Automation"</span> --porcelain</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a><span class="co"># Returns: password_hash</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a><span class="co"># Use in curl request</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a><span class="ex">curl</span> -u admin:password_hash <span class="kw">\</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a><span class="co"># Test authentication</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a><span class="ex">curl</span> -u admin:password_hash <span class="kw">\</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/users/me</span></code></pre>
</div>



<p><strong>Best Practice</strong>: Store credentials in environment variables, never hardcode in scripts.</p>



<div class="sourceCode" id="cb5">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="co"># Set environment variables</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a><span class="bu">export</span> <span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a><span class="bu">export</span> <span class="va">WP_APP_PASSWORD=</span><span class="st">"xxxx xxxx xxxx xxxx"</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a><span class="co"># Use in scripts</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a><span class="ex">curl</span> -u <span class="st">"</span><span class="va">$WP_USER</span><span class="st">:</span><span class="va">$WP_APP_PASSWORD</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span></code></pre>
</div>



<h4 class="wp-block-heading" id="basic-authentication-development-only">Basic Authentication (Development Only)</h4>



<div class="sourceCode" id="cb6">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="co"># Install Basic Auth plugin (development only!)</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a><span class="ex">wp</span> plugin install https://github.com/WP-API/Basic-Auth/archive/master.zip --activate</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a><span class="co"># Use with curl</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a><span class="ex">curl</span> -u username:password <span class="kw">\</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true"></a></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true"></a><span class="co"># NEVER use Basic Auth on production (insecure over HTTP)</span></span></code></pre>
</div>



<h3 class="wp-block-heading" id="create-content">Creating Content via REST API</h3>



<p>Automate content creation using API endpoints.</p>



<h4 class="wp-block-heading" id="create-posts-with-curl">Create Posts with curl</h4>



<div class="sourceCode" id="cb7">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="co"># Create simple post</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a><span class="st">        "title": "New Post via API",</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a><span class="st">        "content": "This post was created via REST API",</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a><span class="st">        "status": "publish"</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a><span class="st">    }'</span> <span class="kw">\</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true"></a></span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true"></a><span class="co"># Create post with categories and tags</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{</span></span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true"></a><span class="st">        "title": "Categorized Post",</span></span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true"></a><span class="st">        "content": "Post content here",</span></span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true"></a><span class="st">        "status": "publish",</span></span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true"></a><span class="st">        "categories": [1, 5],</span></span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true"></a><span class="st">        "tags": [10, 15, 20]</span></span>
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true"></a><span class="st">    }'</span> <span class="kw">\</span></span>
<span id="cb7-23"><a href="#cb7-23" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts</span></code></pre>
</div>



<h4 class="wp-block-heading" id="create-posts-from-external-data">Create Posts from External Data</h4>



<div class="sourceCode" id="cb8">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a><span class="co"># import-from-api.sh - Import content from external API</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a><span class="va">EXTERNAL_API=</span><span class="st">"https://api.example.com/articles"</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a><span class="va">WP_SITE=</span><span class="st">"https://mysite.com"</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a><span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a><span class="va">WP_PASS=</span><span class="st">"app_password"</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true"></a></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true"></a><span class="co"># Fetch external content</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true"></a><span class="ex">curl</span> -s <span class="st">"</span><span class="va">$EXTERNAL_API</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -c <span class="st">'.[]'</span> <span class="kw">|</span> <span class="kw">while</span> <span class="bu">read</span> <span class="va">article</span>; <span class="kw">do</span></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true"></a>    <span class="va">TITLE=$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$article</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -r <span class="st">'.title'</span><span class="va">)</span></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true"></a>    <span class="va">CONTENT=$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$article</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -r <span class="st">'.content'</span><span class="va">)</span></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true"></a></span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Importing: </span><span class="va">$TITLE</span><span class="st">"</span></span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true"></a></span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true"></a>    <span class="co"># Create WordPress post</span></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true"></a>    <span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true"></a>        <span class="ex">-u</span> <span class="st">"</span><span class="va">$WP_USER</span><span class="st">:</span><span class="va">$WP_PASS</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true"></a>        <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true"></a>        <span class="ex">-d</span> <span class="st">"{</span></span>
<span id="cb8-21"><a href="#cb8-21" aria-hidden="true"></a><span class="st">            </span><span class="dt">\"</span><span class="st">title</span><span class="dt">\"</span><span class="st">: </span><span class="dt">\"</span><span class="va">$TITLE</span><span class="dt">\"</span><span class="st">,</span></span>
<span id="cb8-22"><a href="#cb8-22" aria-hidden="true"></a><span class="st">            </span><span class="dt">\"</span><span class="st">content</span><span class="dt">\"</span><span class="st">: </span><span class="dt">\"</span><span class="va">$CONTENT</span><span class="dt">\"</span><span class="st">,</span></span>
<span id="cb8-23"><a href="#cb8-23" aria-hidden="true"></a><span class="st">            </span><span class="dt">\"</span><span class="st">status</span><span class="dt">\"</span><span class="st">: </span><span class="dt">\"</span><span class="st">draft</span><span class="dt">\"</span></span>
<span id="cb8-24"><a href="#cb8-24" aria-hidden="true"></a><span class="st">        }"</span> <span class="kw">\</span></span>
<span id="cb8-25"><a href="#cb8-25" aria-hidden="true"></a>        <span class="st">"</span><span class="va">$WP_SITE</span><span class="st">/wp-json/wp/v2/posts"</span></span>
<span id="cb8-26"><a href="#cb8-26" aria-hidden="true"></a><span class="kw">done</span></span>
<span id="cb8-27"><a href="#cb8-27" aria-hidden="true"></a></span>
<span id="cb8-28"><a href="#cb8-28" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Import complete"</span></span></code></pre>
</div>



<p><strong>Use Case</strong>: Sync content from headless CMS, import RSS feeds, or aggregate content from multiple sources.</p>



<h4 class="wp-block-heading" id="update-posts">Update Posts</h4>



<div class="sourceCode" id="cb9">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="co"># Update post title</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{"title": "Updated Title"}'</span> <span class="kw">\</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts/123</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a><span class="co"># Update post content</span></span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{"content": "New content here"}'</span> <span class="kw">\</span></span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts/123</span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true"></a></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true"></a><span class="co"># Change post status</span></span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb9-17"><a href="#cb9-17" aria-hidden="true"></a>    <span class="ex">-u</span> admin:app_password <span class="kw">\</span></span>
<span id="cb9-18"><a href="#cb9-18" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb9-19"><a href="#cb9-19" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">'{"status": "publish"}'</span> <span class="kw">\</span></span>
<span id="cb9-20"><a href="#cb9-20" aria-hidden="true"></a>    <span class="ex">https</span>://example.com/wp-json/wp/v2/posts/123</span></code></pre>
</div>



<h3 class="wp-block-heading" id="wpcli-rest">WP-CLI REST Commands</h3>



<p>Use WP-CLI’s built-in REST functionality for testing.</p>



<h4 class="wp-block-heading" id="list-rest-routes">List REST Routes</h4>



<div class="sourceCode" id="cb10">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="co"># Show all REST routes</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true"></a><span class="ex">wp</span> rest route list</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true"></a></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true"></a><span class="co"># Show specific namespace</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true"></a><span class="ex">wp</span> rest route list --namespace=wp/v2</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true"></a></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true"></a><span class="co"># Filter routes</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true"></a><span class="ex">wp</span> rest route list <span class="kw">|</span> <span class="fu">grep</span> posts</span></code></pre>
</div>



<h4 class="wp-block-heading" id="execute-rest-requests-with-wp-cli">Execute REST Requests with WP-CLI</h4>



<div class="sourceCode" id="cb11">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="co"># GET request</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a><span class="ex">wp</span> rest get /wp/v2/posts</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a><span class="co"># GET specific post</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a><span class="ex">wp</span> rest get /wp/v2/posts/123</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a><span class="co"># POST request (create content)</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a><span class="ex">wp</span> rest post /wp/v2/posts <span class="kw">\</span></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true"></a>    <span class="ex">--title</span>=<span class="st">"New Post"</span> <span class="kw">\</span></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true"></a>    <span class="ex">--content</span>=<span class="st">"Post content"</span> <span class="kw">\</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true"></a>    <span class="ex">--status</span>=publish</span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true"></a></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true"></a><span class="co"># DELETE request</span></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true"></a><span class="ex">wp</span> rest delete /wp/v2/posts/123 --force=true</span></code></pre>
</div>



<p><strong>Advantage</strong>: WP-CLI REST commands bypass authentication—perfect for local development and testing.</p>



<h3 class="wp-block-heading" id="hybrid-workflows">Hybrid WP-CLI + REST API Workflows</h3>



<p>Combine WP-CLI and REST API for powerful automation.</p>



<h4 class="wp-block-heading" id="content-sync-between-sites">Content Sync Between Sites</h4>



<div class="sourceCode" id="cb12">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true"></a><span class="co"># sync-content-between-sites.sh</span></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true"></a></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true"></a><span class="va">SOURCE_SITE=</span><span class="st">"https://source.com"</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true"></a><span class="va">TARGET_SITE=</span><span class="st">"/var/www/target-site"</span></span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true"></a><span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true"></a><span class="va">WP_PASS=</span><span class="st">"app_password"</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true"></a></span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true"></a><span class="co"># Export posts from source via API</span></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true"></a><span class="ex">curl</span> -s <span class="st">"</span><span class="va">$SOURCE_SITE</span><span class="st">/wp-json/wp/v2/posts?per_page=100"</span> <span class="op">&gt;</span> /tmp/posts.json</span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true"></a></span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true"></a><span class="co"># Import to target with WP-CLI</span></span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true"></a><span class="bu">cd</span> <span class="st">"</span><span class="va">$TARGET_SITE</span><span class="st">"</span></span>
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true"></a></span>
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true"></a><span class="fu">cat</span> /tmp/posts.json <span class="kw">|</span> <span class="ex">jq</span> -c <span class="st">'.[]'</span> <span class="kw">|</span> <span class="kw">while</span> <span class="bu">read</span> <span class="va">post</span>; <span class="kw">do</span></span>
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true"></a>    <span class="va">TITLE=$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$post</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -r <span class="st">'.title.rendered'</span><span class="va">)</span></span>
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true"></a>    <span class="va">CONTENT=$(</span><span class="bu">echo</span> <span class="st">"</span><span class="va">$post</span><span class="st">"</span> <span class="kw">|</span> <span class="ex">jq</span> -r <span class="st">'.content.rendered'</span><span class="va">)</span></span>
<span id="cb12-18"><a href="#cb12-18" aria-hidden="true"></a></span>
<span id="cb12-19"><a href="#cb12-19" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Importing: </span><span class="va">$TITLE</span><span class="st">"</span></span>
<span id="cb12-20"><a href="#cb12-20" aria-hidden="true"></a></span>
<span id="cb12-21"><a href="#cb12-21" aria-hidden="true"></a>    <span class="co"># Use WP-CLI for faster import</span></span>
<span id="cb12-22"><a href="#cb12-22" aria-hidden="true"></a>    <span class="ex">wp</span> post create <span class="kw">\</span></span>
<span id="cb12-23"><a href="#cb12-23" aria-hidden="true"></a>        <span class="ex">--post_title</span>=<span class="st">"</span><span class="va">$TITLE</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb12-24"><a href="#cb12-24" aria-hidden="true"></a>        <span class="ex">--post_content</span>=<span class="st">"</span><span class="va">$CONTENT</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb12-25"><a href="#cb12-25" aria-hidden="true"></a>        <span class="ex">--post_status</span>=publish</span>
<span id="cb12-26"><a href="#cb12-26" aria-hidden="true"></a><span class="kw">done</span></span>
<span id="cb12-27"><a href="#cb12-27" aria-hidden="true"></a></span>
<span id="cb12-28"><a href="#cb12-28" aria-hidden="true"></a><span class="fu">rm</span> /tmp/posts.json</span>
<span id="cb12-29"><a href="#cb12-29" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Content sync complete"</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="headless-wordpress-content-publishing">Headless WordPress Content Publishing</h4>



<div class="sourceCode" id="cb13">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true"></a><span class="co"># headless-publish.sh - Publish to headless WordPress</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true"></a></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true"></a><span class="va">WP_API=</span><span class="st">"https://headless-wp.com/wp-json/wp/v2"</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true"></a><span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true"></a><span class="va">WP_PASS=</span><span class="st">"app_password"</span></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true"></a></span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true"></a><span class="co"># Create content locally with WP-CLI</span></span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true"></a><span class="ex">wp</span> post create <span class="kw">\</span></span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true"></a>    <span class="ex">--post_title</span>=<span class="st">"Headless Post"</span> <span class="kw">\</span></span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true"></a>    <span class="ex">--post_content</span>=<span class="st">"Content here"</span> <span class="kw">\</span></span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true"></a>    <span class="ex">--post_status</span>=draft <span class="kw">\</span></span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true"></a>    <span class="ex">--porcelain</span> <span class="op">&gt;</span> /tmp/post_id.txt</span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true"></a></span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true"></a><span class="va">POST_ID=$(</span><span class="fu">cat</span> /tmp/post_id.txt<span class="va">)</span></span>
<span id="cb13-16"><a href="#cb13-16" aria-hidden="true"></a></span>
<span id="cb13-17"><a href="#cb13-17" aria-hidden="true"></a><span class="co"># Export post data</span></span>
<span id="cb13-18"><a href="#cb13-18" aria-hidden="true"></a><span class="va">POST_DATA=$(</span><span class="ex">wp</span> post get <span class="va">$POST_ID</span> --format=json<span class="va">)</span></span>
<span id="cb13-19"><a href="#cb13-19" aria-hidden="true"></a></span>
<span id="cb13-20"><a href="#cb13-20" aria-hidden="true"></a><span class="co"># Publish via REST API to headless instance</span></span>
<span id="cb13-21"><a href="#cb13-21" aria-hidden="true"></a><span class="ex">curl</span> -X POST <span class="kw">\</span></span>
<span id="cb13-22"><a href="#cb13-22" aria-hidden="true"></a>    <span class="ex">-u</span> <span class="st">"</span><span class="va">$WP_USER</span><span class="st">:</span><span class="va">$WP_PASS</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb13-23"><a href="#cb13-23" aria-hidden="true"></a>    <span class="ex">-H</span> <span class="st">"Content-Type: application/json"</span> <span class="kw">\</span></span>
<span id="cb13-24"><a href="#cb13-24" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">"</span><span class="va">$POST_DATA</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb13-25"><a href="#cb13-25" aria-hidden="true"></a>    <span class="st">"</span><span class="va">$WP_API</span><span class="st">/posts"</span></span>
<span id="cb13-26"><a href="#cb13-26" aria-hidden="true"></a></span>
<span id="cb13-27"><a href="#cb13-27" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Published to headless WordPress"</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="automated-content-moderation">Automated Content Moderation</h4>



<div class="sourceCode" id="cb14">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true"></a><span class="co"># moderate-content.sh - Auto-moderate spam content</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true"></a></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true"></a><span class="va">WP_SITE=</span><span class="st">"/var/www/html"</span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true"></a><span class="va">API_URL=</span><span class="st">"https://example.com/wp-json/wp/v2"</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true"></a><span class="va">WP_USER=</span><span class="st">"admin"</span></span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true"></a><span class="va">WP_PASS=</span><span class="st">"app_password"</span></span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true"></a></span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true"></a><span class="bu">cd</span> <span class="st">"</span><span class="va">$WP_SITE</span><span class="st">"</span></span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true"></a></span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true"></a><span class="co"># Find posts with spam keywords using WP-CLI</span></span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true"></a><span class="va">SPAM_POSTS=$(</span><span class="ex">wp</span> post list <span class="kw">\</span></span>
<span id="cb14-13"><a href="#cb14-13" aria-hidden="true"></a>    <span class="ex">--s</span>=<span class="st">"viagra"</span> <span class="kw">\</span></span>
<span id="cb14-14"><a href="#cb14-14" aria-hidden="true"></a>    <span class="ex">--post_status</span>=publish <span class="kw">\</span></span>
<span id="cb14-15"><a href="#cb14-15" aria-hidden="true"></a>    <span class="ex">--format</span>=ids<span class="va">)</span></span>
<span id="cb14-16"><a href="#cb14-16" aria-hidden="true"></a></span>
<span id="cb14-17"><a href="#cb14-17" aria-hidden="true"></a><span class="kw">for</span> <span class="ex">POST_ID</span> in <span class="va">$SPAM_POSTS</span><span class="kw">;</span> <span class="kw">do</span></span>
<span id="cb14-18"><a href="#cb14-18" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Trashing spam post: </span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb14-19"><a href="#cb14-19" aria-hidden="true"></a></span>
<span id="cb14-20"><a href="#cb14-20" aria-hidden="true"></a>    <span class="co"># Move to trash via REST API</span></span>
<span id="cb14-21"><a href="#cb14-21" aria-hidden="true"></a>    <span class="ex">curl</span> -X DELETE <span class="kw">\</span></span>
<span id="cb14-22"><a href="#cb14-22" aria-hidden="true"></a>        <span class="ex">-u</span> <span class="st">"</span><span class="va">$WP_USER</span><span class="st">:</span><span class="va">$WP_PASS</span><span class="st">"</span> <span class="kw">\</span></span>
<span id="cb14-23"><a href="#cb14-23" aria-hidden="true"></a>        <span class="st">"</span><span class="va">$API_URL</span><span class="st">/posts/</span><span class="va">$POST_ID</span><span class="st">"</span></span>
<span id="cb14-24"><a href="#cb14-24" aria-hidden="true"></a><span class="kw">done</span></span>
<span id="cb14-25"><a href="#cb14-25" aria-hidden="true"></a></span>
<span id="cb14-26"><a href="#cb14-26" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Spam moderation complete"</span></span></code></pre>
</div>



<h3 class="wp-block-heading" id="api-testing">API Testing and Development</h3>



<p>Test custom REST API endpoints during development.</p>



<h4 class="wp-block-heading" id="register-custom-endpoint">Register Custom Endpoint</h4>



<div class="sourceCode" id="cb15">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true"></a><span class="co">// In theme functions.php or plugin</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">'rest_api_init'</span><span class="ot">,</span> <span class="kw">function</span> <span class="ot">()</span> {</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true"></a>    register_rest_route<span class="ot">(</span><span class="st">'custom/v1'</span><span class="ot">,</span> <span class="st">'/data'</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true"></a>        <span class="st">'methods'</span> =&gt; <span class="st">'GET'</span><span class="ot">,</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true"></a>        <span class="st">'callback'</span> =&gt; <span class="st">'custom_api_callback'</span><span class="ot">,</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true"></a>        <span class="st">'permission_callback'</span> =&gt; <span class="st">'__return_true'</span></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true"></a>}<span class="ot">);</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true"></a></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true"></a><span class="kw">function</span> custom_api_callback<span class="ot">()</span> {</span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">array</span><span class="ot">(</span><span class="st">'status'</span> =&gt; <span class="st">'success'</span><span class="ot">,</span> <span class="st">'data'</span> =&gt; <span class="st">'Custom API response'</span><span class="ot">);</span></span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true"></a>}</span></code></pre>
</div>



<h4 class="wp-block-heading" id="test-custom-endpoint">Test Custom Endpoint</h4>



<div class="sourceCode" id="cb16">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true"></a><span class="co"># Test with curl</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true"></a><span class="ex">curl</span> https://example.com/wp-json/custom/v1/data</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true"></a></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true"></a><span class="co"># Test with WP-CLI</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true"></a><span class="ex">wp</span> rest get /custom/v1/data</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true"></a></span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true"></a><span class="co"># Validate response</span></span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true"></a><span class="ex">wp</span> rest get /custom/v1/data <span class="kw">|</span> <span class="ex">jq</span> <span class="st">'.status'</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="automated-api-testing-script">Automated API Testing Script</h4>



<div class="sourceCode" id="cb17">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true"></a><span class="co"># test-api-endpoints.sh</span></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true"></a></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true"></a><span class="va">API_BASE=</span><span class="st">"https://example.com/wp-json/wp/v2"</span></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true"></a></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Testing WordPress REST API endpoints..."</span></span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true"></a></span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true"></a><span class="co"># Test posts endpoint</span></span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true"></a><span class="va">HTTP_CODE=$(</span><span class="ex">curl</span> -s -o /dev/null -w <span class="st">"%{http_code}"</span> <span class="st">"</span><span class="va">$API_BASE</span><span class="st">/posts"</span><span class="va">)</span></span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$HTTP_CODE</span><span class="st">"</span> <span class="ot">-eq</span> 200<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✓ Posts endpoint: OK"</span></span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true"></a><span class="kw">else</span></span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✗ Posts endpoint: FAILED (</span><span class="va">$HTTP_CODE</span><span class="st">)"</span></span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb17-15"><a href="#cb17-15" aria-hidden="true"></a></span>
<span id="cb17-16"><a href="#cb17-16" aria-hidden="true"></a><span class="co"># Test users endpoint</span></span>
<span id="cb17-17"><a href="#cb17-17" aria-hidden="true"></a><span class="va">HTTP_CODE=$(</span><span class="ex">curl</span> -s -o /dev/null -w <span class="st">"%{http_code}"</span> <span class="st">"</span><span class="va">$API_BASE</span><span class="st">/users"</span><span class="va">)</span></span>
<span id="cb17-18"><a href="#cb17-18" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$HTTP_CODE</span><span class="st">"</span> <span class="ot">-eq</span> 200<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb17-19"><a href="#cb17-19" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✓ Users endpoint: OK"</span></span>
<span id="cb17-20"><a href="#cb17-20" aria-hidden="true"></a><span class="kw">else</span></span>
<span id="cb17-21"><a href="#cb17-21" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✗ Users endpoint: FAILED (</span><span class="va">$HTTP_CODE</span><span class="st">)"</span></span>
<span id="cb17-22"><a href="#cb17-22" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb17-23"><a href="#cb17-23" aria-hidden="true"></a></span>
<span id="cb17-24"><a href="#cb17-24" aria-hidden="true"></a><span class="co"># Test categories endpoint</span></span>
<span id="cb17-25"><a href="#cb17-25" aria-hidden="true"></a><span class="va">HTTP_CODE=$(</span><span class="ex">curl</span> -s -o /dev/null -w <span class="st">"%{http_code}"</span> <span class="st">"</span><span class="va">$API_BASE</span><span class="st">/categories"</span><span class="va">)</span></span>
<span id="cb17-26"><a href="#cb17-26" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$HTTP_CODE</span><span class="st">"</span> <span class="ot">-eq</span> 200<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb17-27"><a href="#cb17-27" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✓ Categories endpoint: OK"</span></span>
<span id="cb17-28"><a href="#cb17-28" aria-hidden="true"></a><span class="kw">else</span></span>
<span id="cb17-29"><a href="#cb17-29" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"✗ Categories endpoint: FAILED (</span><span class="va">$HTTP_CODE</span><span class="st">)"</span></span>
<span id="cb17-30"><a href="#cb17-30" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb17-31"><a href="#cb17-31" aria-hidden="true"></a></span>
<span id="cb17-32"><a href="#cb17-32" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"API testing complete"</span></span></code></pre>
</div>



<p>Learn about <a href="https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/">REST API best practices</a> for production.</p>



<h3 class="wp-block-heading" id="next-steps">Next Steps</h3>



<p>You now have WordPress REST API and WP-CLI integration skills for powerful automation workflows.</p>



<h4 class="wp-block-heading" id="recommended-learning-path">Recommended Learning Path</h4>



<p><strong>Week 1</strong>: API fundamentals</p>



<ul class="wp-block-list">
<li>Test endpoints with curl</li>



<li>Set up authentication</li>



<li>Create/update content via API</li>
</ul>



<p><strong>Week 2</strong>: WP-CLI REST commands</p>



<ul class="wp-block-list">
<li>Use <code>wp rest</code> commands</li>



<li>Build hybrid workflows</li>



<li>Test custom endpoints</li>
</ul>



<p><strong>Week 3</strong>: Advanced integration</p>



<ul class="wp-block-list">
<li>Content synchronization</li>



<li>Headless WordPress setup</li>



<li>API-driven automation</li>
</ul>



<p><strong>Week 4</strong>: Production deployment</p>



<ul class="wp-block-list">
<li>Build content pipelines</li>



<li>Implement error handling</li>



<li>Create monitoring systems</li>
</ul>



<h4 class="wp-block-heading" id="advanced-topics">Advanced Topics</h4>



<ol class="wp-block-list">
<li><strong><a href="#">Headless WordPress Architecture</a></strong> &#8211; Complete decoupled setup</li>



<li><strong><a href="#">Custom REST API Endpoints</a></strong> &#8211; Build custom APIs</li>



<li><strong><a href="#">GraphQL + WP-CLI</a></strong> &#8211; Alternative API approach</li>
</ol>



<h4 class="wp-block-heading" id="get-more-resources">Get More Resources</h4>



<p><strong><a href="#">Download API automation scripts</a></strong> including:</p>



<ul class="wp-block-list">
<li>Content sync workflows</li>



<li>API testing suite</li>



<li>Authentication helpers</li>
</ul>



<p><strong><a href="/#get-started">Join our email course</a></strong> for:</p>



<ul class="wp-block-list">
<li>Weekly WP-CLI tutorials</li>



<li>API integration patterns</li>



<li>Modern WordPress architecture</li>
</ul>



<h3 class="wp-block-heading" id="conclusion">Conclusion</h3>



<p>WordPress REST API combined with WP-CLI creates a powerful automation ecosystem for modern WordPress development, from headless setups to complex content workflows.</p>



<p>What we covered:</p>



<p>✅ WordPress REST API basics and authentication <br>✅ Creating and updating content via API <br>✅ WP-CLI REST commands for testing <br>✅ Hybrid WP-CLI + REST API workflows <br>✅ Content sync and automation patterns <br>✅ API testing and development workflows</p>



<p>Master these techniques, and you’ll build sophisticated WordPress automation that integrates with any external system or service.</p>



<p><strong>Ready for more?</strong> Learn <a href="#">WordPress GraphQL integration</a> or <a href="#">headless WordPress architecture</a>.</p>



<p><strong>Questions about WordPress REST API and WP-CLI?</strong> Drop a comment below!</p>



<p><strong>Found this helpful?</strong> Share with other WordPress developers.</p>
<p>The post <a href="https://wpclimastery.com/blog/wordpress-rest-api-wp-cli-complete-automation-integration-guide/">WordPress REST API + WP-CLI: Complete Automation Integration Guide</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
