This repository shows how to call the GoldAPI.io live gold price API using a .NET command-line application written in C#. The example uses HttpClient, System.Text.Json, typed response models, and environment variables for safe API token handling.
Use this example if you are looking for:
- GoldAPI.io .NET example
- GoldAPI.io C# integration
- .NET Core gold price API example
- Live XAU/USD price API with C#
- Precious metals API example for .NET
- Gold price API command-line application
This project targets .NET 10 with net10.0, the latest LTS release listed by Microsoft as of April 23, 2026. Microsoft lists .NET 10 as Long Term Support, supported until November 2028.
Note: modern releases are branded as
.NET, not.NET Core;.NET Core 3.1was the last version to use the old naming.
The example calls:
https://www.goldapi.io/api/XAU/USDEquivalent curl request:
curl -X GET "https://www.goldapi.io/api/XAU/USD" \
-H "x-access-token: GOLD_API_TOKEN"- .NET 10 SDK or newer
- A GoldAPI.io API token
Run the command-line app:
GOLD_API_TOKEN=your_goldapi_token_here dotnet runYou can also change the metal and currency pair:
GOLD_API_TOKEN=your_goldapi_token_here GOLD_API_METAL=XAU GOLD_API_CURRENCY=USD dotnet runThe core GoldAPI.io request is:
using var httpClient = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://www.goldapi.io/api/XAU/USD");
request.Headers.Add("x-access-token", Environment.GetEnvironmentVariable("GOLD_API_TOKEN"));
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
using var response = await httpClient.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();This repository expands that into a complete typed .NET console application with:
GoldApiResponseC# record- JSON mapping with
System.Text.Json - Basic HTTP error handling
- Configurable
GOLD_API_METALandGOLD_API_CURRENCY - Token handling through environment variables
{
"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
}| Variable | Required | Default | Description |
|---|---|---|---|
GOLD_API_TOKEN |
Yes | None | Your GoldAPI.io access token. |
GOLD_API_METAL |
No | XAU |
Metal symbol to request. |
GOLD_API_CURRENCY |
No | USD |
Currency symbol to request. |
dotnet buildDo not commit your GoldAPI.io token to GitHub. Store it in environment variables, GitHub Actions secrets, or a local .env file that is ignored by Git.
This example is intended for server-side .NET. Do not expose private GoldAPI.io tokens in client-side applications.
MIT