How to integrate external APIs on Webflow

intermediate 12 min read Updated 2026-03-18
Quick Answer

Integrate external APIs in Webflow by adding custom JavaScript code to your site using embedded HTML elements or the custom code sections. Use fetch() or XMLHttpRequest to call APIs and display the data dynamically on your Webflow pages.

Prerequisites

  • Basic understanding of APIs and JSON
  • Webflow Designer access
  • JavaScript fundamentals
  • API keys from external service

Step-by-Step Instructions

1

Set up your API credentials and test endpoint

Before integrating into Webflow, test your API endpoint using a tool like Postman or your browser's developer console. Note your API key, endpoint URL, and required headers. Store sensitive credentials securely - never expose API keys in client-side code for production sites.
Use environment variables or server-side proxies for sensitive API keys in production
2

Add HTML Embed element to your page

In the Webflow Designer, drag an HTML Embed element from the Components panel to where you want your API data to appear. This element will contain both the HTML structure and JavaScript code for your API integration. Size the embed element appropriately for your content.
You can also use the page-level custom code sections in Site Settings for site-wide API integrations
3

Create the HTML structure for displaying data

Inside the HTML Embed element, create the HTML structure where your API data will be displayed:

<div id="api-container">
  <div id="loading">Loading...</div>
  <div id="api-data"></div>
  <div id="error" style="display:none;"></div>
</div>

This provides containers for loading states, data display, and error handling.
Use semantic HTML elements and IDs that clearly describe their purpose
4

Write JavaScript to fetch API data

Add JavaScript code within <script> tags in your HTML Embed to make the API call:

<script>
async function fetchAPIData() {
  try {
    const response = await fetch('YOUR_API_ENDPOINT', {
      method: 'GET',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      }
    });
    const data = await response.json();
    displayData(data);
  } catch (error) {
    handleError(error);
  }
}
</script>
Always include error handling and consider rate limiting for your API calls
5

Create functions to display and handle data

Add functions to process and display the API response data:

function displayData(data) {
  const container = document.getElementById('api-data');
  const loading = document.getElementById('loading');
  
  loading.style.display = 'none';
  container.innerHTML = '';
  
  data.forEach(item => {
    const element = document.createElement('div');
    element.innerHTML = `<h3>${item.title}</h3><p>${item.description}</p>`;
    container.appendChild(element);
  });
}
Sanitize any user-generated content from APIs to prevent XSS attacks
6

Add error handling and loading states

Implement proper error handling and user feedback:

function handleError(error) {
  const loading = document.getElementById('loading');
  const errorDiv = document.getElementById('error');
  
  loading.style.display = 'none';
  errorDiv.style.display = 'block';
  errorDiv.innerHTML = 'Failed to load data. Please try again later.';
  console.error('API Error:', error);
}

This provides users with helpful feedback when API calls fail.
Log detailed errors to the console for debugging while showing user-friendly messages
7

Initialize API call and test integration

Add an initialization function that runs when the page loads:

document.addEventListener('DOMContentLoaded', function() {
  fetchAPIData();
});

Save your HTML Embed element and Publish your site to test the API integration. Check the browser's Developer Tools Console for any errors and verify that data displays correctly.
Test your integration on the published site, as some APIs may not work in Webflow's preview mode
8

Style and optimize the integration

Use Webflow's Designer to style the container elements, or add CSS within your HTML Embed:

<style>
#api-container {
  padding: 20px;
  border-radius: 8px;
}
#loading {
  text-align: center;
  color: #666;
}
</style>

Consider adding refresh buttons, pagination, or caching mechanisms for better user experience.
Use Webflow's responsive design tools to ensure your API content looks good on all devices

Common Issues & Troubleshooting

CORS (Cross-Origin Resource Sharing) errors preventing API calls

Use a server-side proxy or a service like CORS Anywhere for development. For production, configure your API server to allow your Webflow domain, or use serverless functions as a proxy.

API data not displaying after publishing

Check the browser's Developer Tools Console for JavaScript errors. Ensure your API endpoint is accessible via HTTPS and that all variable names match between your HTML structure and JavaScript functions.

API calls working intermittently or timing out

Implement retry logic with exponential backoff: setTimeout(() => fetchAPIData(), 2000) on failure. Check your API provider's rate limits and add appropriate delays between requests.

Sensitive API keys exposed in client-side code

Move sensitive operations to serverless functions (Netlify Functions, Vercel API routes) or use a backend service. Only expose public API keys in client-side Webflow code, and implement proper API key restrictions.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official Webflow website before purchasing.