Integrating GoldAPI.io with Webflow
Webflow is useful when you want to show live precious metals prices on a marketing site, landing page, directory, or customer-facing pricing page.
The safest approach is to fetch GoldAPI.io through your own backend endpoint and then render the returned price in Webflow with a small custom script. This keeps your API key private.
What you need
- A Webflow site.
- A GoldAPI.io API key.
- A small backend endpoint or serverless function that calls GoldAPI.io.
- A Webflow Embed element or custom code block.
Step 1: Create a backend endpoint
Create an endpoint on your own backend, for example:
https://example.com/api/metals/goldThat endpoint should call GoldAPI.io server-side:
app.get('/api/metals/gold', async (req, res) => {
const response = await fetch('https://www.goldapi.io/api/price/XAU/USD?melt_price=false¤cy_info=false', {
headers: {
'x-access-token': process.env.GOLDAPI_API_KEY,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
res.status(response.status).json({ error: 'Price unavailable' });
return;
}
const data = await response.json();
res.json({
metal: 'XAU',
currency: 'USD',
price: data.price,
ask: data.ask,
bid: data.bid,
timestamp: data.timestamp
});
});Step 2: Add price placeholders in Webflow
Add text elements where you want the price to appear, then give them custom attributes such as:
data-goldapi-field="price"
data-goldapi-field="bid"
data-goldapi-field="ask"For example:
<span data-goldapi-field="price">Loading...</span>Step 3: Add custom code in Webflow
Add this script before the closing body tag in Webflow page settings or site-wide custom code:
<script>
async function loadGoldPrice() {
const response = await fetch('https://example.com/api/metals/gold');
if (!response.ok) {
return;
}
const data = await response.json();
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: data.currency
});
document.querySelectorAll('[data-goldapi-field="price"]').forEach((element) => {
element.textContent = formatter.format(data.price);
});
document.querySelectorAll('[data-goldapi-field="bid"]').forEach((element) => {
element.textContent = formatter.format(data.bid);
});
document.querySelectorAll('[data-goldapi-field="ask"]').forEach((element) => {
element.textContent = formatter.format(data.ask);
});
}
loadGoldPrice();
</script>Replace https://example.com/api/metals/gold with your own backend endpoint.
Step 4: Refresh the price automatically
If the page stays open for a long time, refresh the value on an interval:
<script>
loadGoldPrice();
setInterval(loadGoldPrice, 60000);
</script>This refreshes the displayed price every 60 seconds.
Example use cases
You can use this Webflow setup to:
- show live gold and silver prices on a landing page
- update bullion or jewelry pricing sections
- display bid and ask values on a trading information page
- add live market data to a customer portal or gated page
Security note
Do not place your GoldAPI.io key directly in Webflow custom code. Browser-side code is visible to visitors. Keep the key on your backend or serverless function and expose only the price fields your Webflow page needs.
Conclusion
Webflow works well with GoldAPI.io when the API call is handled server-side. A backend endpoint plus a small Webflow script is enough to display real-time gold and silver prices without exposing your API key.
