An API key is a secret token that identifies or authorizes an application when it calls an external API. Servers use keys to verify requesters, prevent abuse, and reduce impersonation. section 9.3.1
Use an API key as part of a documented request workflow:
- Create an account with the API provider and obtain a key; generation and authentication details differ between APIs. section 9.3.1
- Place the key in the request's required key/value parameters, often through a PowerShell hashtable passed to -Body. section 9.3.1
- Keep keys out of scripts when possible by retrieving them from SecretManagement, Jenkins credential stores, or another protected vault. section 4.5 section 4.4.1
- Test the API connection separately before combining it with a larger automation, and account for permissions, output exposure, and changing requirements. section 4.4.1 section 4.5
Geolocation lookup
A PowerShell script retrieves a public IP address, builds a hashtable containing apiKey and ipAddress, and passes it to Invoke-RestMethod. The returned location can populate a Word document with the country and city. section 9.3.1
$apiKey = "your_API_key"
$ApiUrl = "https:/ /geo.ipify.org/api/v2/country,city"
$Body = @{
apiKey = $apiKey
ipAddress = $IP.ip
}
$geoData = $null
$geoData = Invoke-RestMethod -Uri $ApiUrl -Body $Body
$geoData.location
country : US
region : Illinois
city : Chicago
lat : 41.94756
lng : -87.65650
postalCode : 60613
timezone : -05:00
Inspect the complete request pattern: assign the key, construct the API URL and body, call Invoke-RestMethod, and read the location result. section 9.3.1












