0

I am currently doing some basic API REST test with powershell.

However, I am having an issue with capturing a specific output data

For example:

$bearer = Invoke-RestMethod -Method POST -Body $body -uri "https://api.yourwebsite.com/oauth/token"

Output:

access_token
------------
{longtokenhere}

But when using it with the header:

$header = @{Authorization = "Bearer "+$bearer}

Output is:

Name                           Value
----                           -----
Authorization                  Bearer @{access_token={longtokenhere}}

I would like to know how will I be able to remove the " @{access_token=}" part so I can just use the {longtokehere} only?

Paolo
  • 21,270
  • 6
  • 38
  • 69

1 Answers1

1

I did some testing and it turns out I can directly call out the access_token output:

When I did this part:

$bearer = Invoke-RestMethod -Method POST -Body $body -uri "https://api.yourwebsite.com/oauth/token"

Output:

access_token
------------
{longtokenhere}

I just simpley used this one:

$bearer.access_token

And I got the direct output of the token only:

{longtokenhere}

My final command worked with this:

Invoke-RestMethod -Method GET -Header @{Authorization = "Bearer "+$bearer.access_token} -ContentType "application/json" -uri "https://api.yourwebsite.com/release/releaseID"