# Powershell Invoke-restmethod

**URL:** <https://www.epiusers.help/t/powershell-invoke-restmethod/123150>\
**Category:** Epicor ERP 10\
**Tags:** baq\
**Created:** [February 12, 2025, 12:53am UTC](https://www.epiusers.help/t/powershell-invoke-restmethod/123150 "2025-02-12T00:53:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RMH148](https://www.epiusers.help/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@RMH148](https://www.epiusers.help/u/RMH148)\
**Post date:** [February 12, 2025, 12:53am UTC](https://www.epiusers.help/t/powershell-invoke-restmethod/123150/1 "2025-02-12T00:53:35Z")

</div>

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](https://centralusdtapp46.epicorsaas.com/SaaSxxx/api/v1/BaqSvc/INV-PartBin)”  
$Data = Invoke-RestMethod $uriPartBin -Method Get -Credential $cred -ContentType “Application/Json”

---

<div class="post-metadata">

**Author:** ![Hally](https://www.epiusers.help/user_avatar/www.epiusers.help/hally/32/1263_2.png) [@Hally](https://www.epiusers.help/u/Hally)\
**Post date:** [February 12, 2025, 12:04pm UTC](https://www.epiusers.help/t/powershell-invoke-restmethod/123150/2 "2025-02-12T12:04:40Z")

</div>

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.
