Search

PowerShell GET from REST API

PowerShell has a great command called Invoke-RestMethod. With this command, you can:

  • Delete
  • Get
  • Head
  • Merge
  • Options
  • Patch
  • Post
  • Put
  • Trace

For this guide, we will focus on Get.

In this script, we are going to make a call to Coinbase’s free and public REST API for currency and cryptocurrencies’ exchange rates, since that’s a current topic. Basically, we are asking the Coinbase API what 1 USD is in all of their tracked currencies.

# Set the currency we want to convert to
$Currency = "usd"

# Set the endpoint URL the API is on, useing the $Currency variable to fill in our currency
$RestURL = "https://api.coinbase.com/v2/exchange-rates?currency=$Currency"

# Use Invoke-RestMethod with 'Get' to "get" the data and save it in memory to the $Response variable
$Response = Invoke-RestMethod -Method Get -Uri $RestURL

# Show the data for $Response in the PowerShell console 
$Response.data.rates

If everything goes well you will get a response like this (note I truncated for length)

AED     : 3.6730001432470056
AFN     : 86.9884427155008186
ALL     : 115.4575756911001837
AMD     : 481.6158500000022236
ANG     : 1.8027240000000001
AOA     : 409.2007999999973372
ARS     : 117.859344301323914
AUD     : 1.4345145999999999
AWG     : 1.7999999999999999
AZN     : 1.6999999999999999
BAM     : 1.874639
BBD     : 2.018492622005768
BDT     : 87.5406845331367753
BGN     : 1.8741739999999999
BHD     : 0.3770022
BIF     : 2042.9009193054136874
BMD     : 1
BND     : 1.3935169133934812
BOB     : 6.8815911449887255
...

In this case, at this time of writing, 1 USD = 3.6730001432470056 AED (crypto is near the bottom of the list in your output). That’s it! From here you can do whatever you want with that data (like convert it to a CSV). Pretty neat!

Share the Post:

Related Posts

The Infinite Forbidden Set Stats

Yu-Gi-Oh! The Infinite Forbidden launched in the TCG on July 19, 2024. I’ve been excited for this set since its announcement because of the nostalgia-bait of Exodia. As a core set, it’s full of new cards, strategies, and archetypes. The highly anticipated Fiendsmith makes its TCG debut just in time for the Yu-Gi-Oh! NAWCQ. Exodia, White Forest, and Gimmick Puppet get support, and a new TCG-exclusive archetype called Mimighoul makes its debut.

Read More

Help! I’m Missing haptic feedback in Beat Saber

The haptic feedback in Beat Saber just stopped working. I knew it wasn’t the controller since vibrations were working outside of Steam or Beat Saber. I didn’t realize how much the haptic feedback contributed to VR immersion, but wow, did I miss it.

Read More