Skip to content

goldapi-io/gold-api-examples-excel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoldAPI.io Microsoft Excel Example: Live Gold Price API

This repository shows how to call the GoldAPI.io live gold price API from Microsoft Excel. It includes examples for Office Scripts, Power Query, VBA, and Excel custom functions so you can choose the integration style that fits your workbook.

Use this example if you are looking for:

  • GoldAPI.io Microsoft Excel example
  • GoldAPI.io Office Scripts integration
  • GoldAPI.io Power Query example
  • GoldAPI.io VBA macro example
  • GoldAPI.io Excel custom function example
  • Live gold price API in Excel
  • XAU/USD API request sample for spreadsheets
  • Precious metals API example for Excel workbooks

API Endpoint

The examples call:

https://www.goldapi.io/api/XAU/USD

Equivalent curl request:

curl -X GET "https://www.goldapi.io/api/XAU/USD" \
  -H "x-access-token: GOLD_API_TOKEN"

Requirements

  • Microsoft Excel
  • A GoldAPI.io API token
  • One of these Excel integration options:
    • Office Scripts in Excel on the web
    • Power Query in Excel
    • VBA macros in desktop Excel
    • Office Add-in custom functions

Option 1: Office Scripts

Use office-scripts/gold-api-example.ts when you want a modern script that writes live GoldAPI.io data into a worksheet.

  1. Open Excel on the web.
  2. Open the Automate tab.
  3. Create a new script.
  4. Paste the contents of office-scripts/gold-api-example.ts.
  5. Run the script and enter your GoldAPI.io token when prompted.

The script creates or updates a worksheet named GoldAPI with a summary table and the full JSON response.

Option 2: Power Query

Use power-query/GoldApiExample.pq when you want a refreshable query table in Excel.

  1. Create a one-cell named range or table named GoldApiToken containing your GoldAPI.io token.
  2. Open Power Query.
  3. Create a blank query.
  4. Open Advanced Editor.
  5. Paste the contents of power-query/GoldApiExample.pq.
  6. Load the query into a worksheet.

You can change Metal and Currency in the query from XAU and USD to another supported pair.

Option 3: VBA

Use vba/GoldApiExample.bas when you want a desktop Excel macro.

  1. Open Excel desktop.
  2. Press Alt+F11 on Windows to open the VBA editor.
  3. Import vba/GoldApiExample.bas, or paste its contents into a module.
  4. Replace your_goldapi_token_here with your GoldAPI.io token.
  5. Run FetchGoldPrice.

The VBA example uses WinHttp.WinHttpRequest.5.1, which is intended for Excel on Windows. It writes a summary table and the full JSON response to a worksheet named GoldAPI.

Option 4: Custom Function

Use custom-functions/functions.ts when you want a worksheet function:

=GOLDPRICE("XAU","AUD")

This option is for an Excel Office Add-in custom function. The function reads the GoldAPI.io token from Office add-in storage and returns the current price value for the requested metal and currency.

The supporting metadata is in custom-functions/functions.json. See custom-functions/README.md for token setup notes.

Office Scripts Example

The core GoldAPI.io request is:

const response = await fetch("https://www.goldapi.io/api/XAU/USD", {
  method: "GET",
  headers: {
    "x-access-token": goldApiToken,
    Accept: "application/json",
  },
});

const data = await response.json();

This repository expands that into an Excel example with:

  • Worksheet creation
  • Summary fields for price, bid, ask, change, exchange, and symbol
  • Full JSON response output
  • Configurable metal and currency pair
  • Basic HTTP error handling

The custom function example returns a scalar price directly to the worksheet:

=GOLDPRICE("XAU","AUD")

Sample GoldAPI.io Response

{
  "timestamp": 1776907250,
  "metal": "XAU",
  "currency": "USD",
  "exchange": "FOREXCOM",
  "symbol": "FOREXCOM:XAUUSD",
  "prev_close_price": 4739.215,
  "open_price": 4739.215,
  "low_price": 4694.355,
  "high_price": 4753.79,
  "open_time": 1776902400,
  "price": 4733.125,
  "ch": -6.09,
  "chp": -0.13,
  "ask": 4733.72,
  "bid": 4732.69,
  "price_gram_24k": 152.1735,
  "price_gram_22k": 139.4924,
  "price_gram_21k": 133.1518,
  "price_gram_20k": 126.8113,
  "price_gram_18k": 114.1301,
  "price_gram_16k": 101.449,
  "price_gram_14k": 88.7679,
  "price_gram_10k": 63.4056
}

Configuration

Setting Required Default Description
GoldAPI token Yes None Your GoldAPI.io access token.
Metal No XAU Metal symbol to request.
Currency No USD Currency symbol to request.

Security Note

Do not commit your GoldAPI.io token to GitHub or share workbooks that contain private API tokens.

For Office Scripts, pass the token as a script parameter. For Power Query, use a workbook parameter and avoid committing workbook files. For VBA, avoid hard-coding production tokens in files that will be shared. For custom functions, store the token in add-in storage or retrieve it from your own backend instead of putting it in worksheet formulas.

License

MIT

About

Excel + Power Query + VBA GoldAPI integration example. Get live gold/silver prices in Excel.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors