How to Integrate 3rd-Party APIs with WordPress (Clear Guide + Examples)
Integrating APIs with WordPress allows your website or WooCommerce store to exchange data with external systems: CRMs, ERPs, shipping providers, AI tools, spreadsheets, booking systems, and more.
Below you’ll find practical, real-world examples with code, including how to use WooCommerce webhooks to push orders into Google Sheets.
1. Basic API Request in WordPress (Clear Example)
The simplest way to call an API is using WordPress’s built-in wp_remote_get() and wp_remote_post().
$response = wp_remote_get( 'https://api.example.com/products' );
if ( is_wp_error( $response ) ) return;
$data = json_decode( wp_remote_retrieve_body( $response ), true );
// Use the data
foreach ( $data as $item ) {
// Do something with $item
}
$body = [
'email' => 'user@example.com',
'name' => 'John Doe'
];
$response = wp_remote_post( 'https://api.crm.com/create-lead', [
'headers' => [
'Authorization' => 'Bearer API_KEY',
'Content-Type' => 'application/json'
],
'body' => json_encode($body)
]);
This is the core of most WordPress integrations.
2. Example: WooCommerce → Google Sheets via API (Practical)
This uses:
- WooCommerce Webhooks (trigger)
- Google Apps Script (receiver)
- API POST request (data transfer)
Step 1 — Create a Webhook in WooCommerce
WooCommerce → Settings → Advanced → Webhooks → Add webhook
- Topic: Order Created
- Delivery URL:
https://script.google.com/macros/s/YOUR_SCRIPT_ID/exec - Format: JSON
WooCommerce will now POST order data to your Google Script.
Step 2 — Google Apps Script to receive WooCommerce order
Paste this code into your Google Apps Script:
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Orders");
sheet.appendRow([
new Date(),
data.id,
data.billing.first_name,
data.billing.last_name,
data.total,
data.payment_method_title
]);
return ContentService.createTextOutput("OK");
}
Now every new order will automatically appear in Google Sheets.
✔ Fully automated
✔ Real-time synchronization
✔ No plugin needed
3. Example: Sync WooCommerce Stock with an ERP API
Step 1 — Call ERP for updated stock
function sync_erp_stock() {
$response = wp_remote_get('https://erp.com/api/stock?token=API_KEY');
if (is_wp_error($response)) return;
$data = json_decode(wp_remote_retrieve_body($response), true);
foreach ($data as $item) {
$product = wc_get_product_id_by_sku($item['sku']);
if ($product) {
wc_update_product_stock($product, $item['qty']);
}
}
}
Step 2 — Run it via server cron
This avoids WP-Cron unreliability.
*/15 * * * * wget https://your-site.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
4. Example: Sync Contact Form 7 Submissions to a CRM
Integrate through API when the form is submitted:
add_action('wpcf7_mail_sent', function($contact_form) {
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
wp_remote_post('https://crm.com/api/leads', [
'headers' => [
'Authorization' => 'Bearer API_KEY',
'Content-Type' => 'application/json'
],
'body' => json_encode([
'name' => $data['your-name'],
'email' => $data['your-email'],
'phone' => $data['your-phone']
])
]);
});
Now all CF7 leads get synced into the CRM instantly.
5. Example: Display External Data on WordPress Pages
Fetch cryptocurrency price and show it on the site:function btc_price_shortcode() {
$cache = get_transient('btc_price');
if ($cache) return $cache;
$response = wp_remote_get('https://api.coindesk.com/v1/bpi/currentprice.json');
if (is_wp_error($response)) return "Error";
$data = json_decode(wp_remote_retrieve_body($response), true);
$price = $data['bpi']['USD']['rate'];
set_transient('btc_price', $price, 300);
return "BTC Price: $".$price;
}
add_shortcode('btc_price', 'btc_price_shortcode');
✔ Cached
✔ Fast
✔ Works anywhere in WordPress
6. Best Practices for API Integrations
✔ Use transients or object cache
Avoid API limits and speed issues.
✔ Use server cron for scheduled sync
Never rely on WP-cron for real-time APIs.
✔ Log all failures
So you can debug API errors.
✔ Use queues for large imports
For example: syncing 10,000 products from ERP → WooCommerce.
✔ Secure API keys
Store them in:
- wp-config.php
- encryption
- ACF options
7. Popular Real Integrations We Build as an Agency
WooCommerce
- API sync with ERP/CRM
- Shipping label creation (DHL, UPS, NovaPoshta)
- Google Sheets sync via webhook
- Marketplace product imports
WordPress
- Real estate listings from API
- AI text generators (OpenAI, Gemini, Claude)
- Weather & live statistics
- Booking availability API
Automations
- CRM automations (HubSpot, Zoho, Bitrix24)
- Inventory updates every 5–10 minutes
- Payment system callbacks