Powershell Invoke-restmethod

I have working powershell script that uses username and password to run baq to $data, what I need is to figure out how to run the same baq using x-api-key (token). here is working code:

$user = “xxxxxx”
$Pass = “xxxxxx”

#Create encoded password
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
#Create Credential
$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)

$uriPartBin = “https://centralusdtapp46.epicorsaas.com/SaaSxxx/api/v1/BaqSvc/INV-PartBin
$Data = Invoke-RestMethod $uriPartBin -Method Get -Credential $cred -ContentType “Application/Json”

You are going to need to use v2 instead of v1. Then get the token as a first step.

There are details in the help with regards to REST and using Tokens if I recall.