Using Deployments API with Powershell

Hi Team,

How can I post/get on Jira deployment API using powershell. Do I need to create a webhook to deployment tool or directly use OAuth to do it. my Oauth Works for main jira cloud but does not work on deployment API

here is the sample code below

$pair = “username:password/APIToken”
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = “Basic $base64”
$headers = @{ Authorization = $basicAuthValue }

#
Invoke-RestMethod -Uri https://xxxx.atlassian.net/rest/api/2/project -Method Get -Headers $headers
#output we get
expand : description,lead,issueTypes,url,projectKeys,permissions,insight
self : vnbnb
id : 11103
key : ATCMVFOSR
name : Ability to Capture Multi-Value fields on SIM Records
avatarUrls : @{48x48=cgcgg;}

projectTypeKey : software
simplified : True
style : next-gen
isPrivate : False
properties :
entityId : 45e89b72-1c54-4a04-a380-962d46da37fe
uuid : 45e89b72-1c54-4a04-a380-962d46da37fe

#

Invoke-RestMethod -Uri https://xxxx.atlassian.net/rest/deployments/0.1/pipelines/19/environments/US_QA_2023.1.0.93/deployments/19 -Method Get -Headers $headers

#output we get
Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At line:7 char:5

  • Invoke-RestMethod -Uri xxx.atlassian.net/rest/depl ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I am able to use Jira deployment api using jira key