API integration in WordPress means connecting your site to other software through their APIs, so data and actions move between them automatically. A WordPress site can consume an external API, for example a payment, CRM or shipping service, and it can expose its own data through the built-in REST API or custom endpoints so that other systems and apps can use it. Done well, it removes manual work and keeps systems consistent. Done carelessly, it adds slow pages, security holes and fragile sync.
In short: start with the REST API WordPress already has, authenticate properly, validate and sanitise everything, keep API keys out of front-end code, cache responses with a fallback for outages, prefer webhooks and background jobs to constant polling, log failures, and treat each integration as something to monitor and maintain.
What is an API, and why connect it to WordPress?
An API (application programming interface) is a defined way for one program to ask another for data or to request an action. Think of a waiter: you place an order, the waiter takes it to the kitchen and brings back the result, without you entering the kitchen. Typical WordPress integrations connect:
- Payment and invoicing services.
- CRM, marketing automation and email platforms.
- Shipping, ERP and inventory systems.
- Search, maps and analytics services.
- Mobile apps or separate front ends that read WordPress content (headless setups).
- Partner or data feeds, such as rates, odds or product catalogues.
The benefits are current data, automated workflows and fewer copy-and-paste errors. The costs are extra moving parts that can fail, so decide what the integration must do and what happens when it does not work.
What is the WordPress REST API?
WordPress has a REST API built into core. It exposes site content and settings as JSON through endpoints under /wp-json/, using standard HTTP methods:
- GET retrieves data, for example /wp-json/wp/v2/posts for a list of posts or /wp-json/wp/v2/posts/123 for one.
- POST creates data.
- PUT or PATCH updates data.
- DELETE removes data.
Reading public content needs no login. Creating, changing or reading private data requires authentication and the right permissions. Plugins add their own endpoints too, for example WooCommerce. See what WooCommerce endpoints are and how to create an API in WooCommerce.
How does authentication work?
The WordPress REST API authentication guide describes the options:
- Cookie authentication with a nonce: the default for logged-in users when code runs inside WordPress. It does not work for external applications.
- Application Passwords: introduced in WordPress 5.6. They are generated per user for an application, can be revoked individually and are sent over HTTPS using Basic Auth. This is the simplest option for server-to-server calls.
- OAuth and JWT: are not part of core. They are available through plugins when you need token-based access for third-party applications.
Give each integration its own user with only the capabilities it needs, and revoke credentials when an integration ends. Never use an administrator account for an integration.
How do you create a custom endpoint?
Use register_rest_route inside the rest_api_init hook. Three details matter. First, always set a permission_callback. A route without one is treated as public, and since WordPress 5.5 a missing callback triggers a notice. See WordPress 5.5 REST API changes. Use __return_true only for data that really is public, and a capability check such as current_user_can for everything else. Second, validate and sanitise parameters. Third, return clean errors that do not reveal internals.
add_action( 'rest_api_init', function () {
register_rest_route( 'wlc/v1', '/orders-summary', array(
'methods' => 'GET',
'callback' => 'wlc_orders_summary',
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
'args' => array(
'days' => array(
'default' => 7,
'validate_callback' => function ( $v ) { return is_numeric( $v ) && $v > 0 && $v <= 90; },
'sanitize_callback' => 'absint',
),
),
) );
} );
Use a unique namespace with a version, such as wlc/v1, so you can change the API later without breaking clients.
How do you call a third-party API from WordPress?
Use the WordPress HTTP API, such as wp_remote_get and wp_remote_post, which handle transport details and return a WP_Error on failure. Set a timeout, check the response code, not only the absence of an error, and decode the body defensively. Cache responses with the Transient API so that every page view does not trigger a remote call, and keep a last-known-good copy for when the service is down.
function wlc_get_rates() {
$cached = get_transient( 'wlc_rates' );
if ( false !== $cached ) {
return $cached;
}
$response = wp_remote_get( 'https://api.example.com/rates', array(
'timeout' => 8,
'headers' => array( 'Authorization' => 'Bearer ' . WLC_API_KEY ),
) );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
return get_option( 'wlc_rates_last_good', array() );
}
$data = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! is_array( $data ) ) {
return get_option( 'wlc_rates_last_good', array() );
}
set_transient( 'wlc_rates', $data, 10 * MINUTE_IN_SECONDS );
update_option( 'wlc_rates_last_good', $data, false );
return $data;
}
Store keys in configuration, for example constants in wp-config.php or environment variables, and not in code you commit or in JavaScript sent to the browser. If the browser needs data from a protected API, call it from the server and expose only a narrow endpoint of your own.
How do you keep systems in sync?
- Polling: your site asks the other system at intervals. Simple, but wasteful and delayed, and it can hit rate limits.
- Webhooks: the other system calls an endpoint on your site when something changes. Faster and cheaper, but you must verify the signature or secret of every request and handle duplicates and retries safely.
- Background jobs: move slow or non-critical work off the page request. WordPress offers WP-Cron, which depends on site traffic unless you trigger it from the server, and the Action Scheduler library, which WooCommerce bundles, offers a queue with retries.
- Idempotency: design handlers so that processing the same event twice does no harm.
What problems should you expect?
- Rate limits: batch and cache requests, and back off on errors.
- Slow or unavailable services: timeouts, fallbacks and background processing, so a remote outage does not take your pages down.
- Data mismatches: agree on identifiers, formats, time zones and which system is the source of truth.
- Security: unauthenticated endpoints, leaked keys, unvalidated input. See WordPress security.
- Versioning: providers change or retire API versions, so watch announcements and test updates.
- Debugging: log requests, responses and failures with identifiers, without storing secrets or personal data in logs.
When is a plugin enough, and when do you need custom work?
A maintained plugin or connector is often enough for common cases, such as sending form entries to a CRM or syncing orders to an accounting tool. Custom development makes sense when the data model is specific, volumes are high, several systems must stay consistent, performance or security requirements are strict, or the available plugins add more weight than the task is worth. See levels of WordPress customisation for how to decide.
What about headless WordPress?
In a headless setup, WordPress holds the content and a separate application renders the front end by reading the REST API (or another API). It suits teams that need a custom front end or several channels from one content source, and it adds a second system to host, secure and monitor. Choose it for a clear reason, not as a default.
How do you test and maintain integrations?
- Write down the contract: endpoints, data fields, error cases and expected volumes.
- Test against the provider’s sandbox, including failures and timeouts.
- Add monitoring and alerts for failed calls, queue backlogs and slow responses.
- Review keys, permissions and logs regularly.
- Retest after WordPress, plugin and provider updates.
- Document who owns each integration.
Need help with an integration?
We design and build integrations as part of WordPress development, including custom endpoints, third-party connections, webhooks and background processing. An audit can review existing integrations for security and reliability, performance work addresses slow remote calls, and ongoing growth and care covers monitoring and updates. For industry examples, see which APIs are essential in iGaming software integration.
FAQ
What is API integration in WordPress?
Connecting a WordPress site to other software through APIs so data and actions move between them automatically, in either direction.
Does WordPress have a built-in API?
Yes. The REST API is part of WordPress core and exposes content under /wp-json/. Plugins can add their own endpoints.
How do I authenticate API requests to WordPress?
Use cookie authentication with a nonce inside WordPress, and Application Passwords over HTTPS for external applications. OAuth and JWT require plugins.
Is it safe to make a custom endpoint public?
Only for data that is truly public. Set a permission_callback, validate input and avoid exposing internals.
Should I use webhooks or polling?
Prefer webhooks where the provider supports them, with signature checks and safe handling of duplicates. Use polling when webhooks are not available.
How do I stop an API from slowing my site?
Cache responses, set timeouts, move non-critical calls to background jobs and keep a fallback for outages.



