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?

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.