Change "curl" command to work with PowerShell Invoke-WebRequest (TeamForge API)

678 Views Asked by At

I am attempting to use the TeamForge API. This is my first dip into web requests so I am sure I am missing something obvious.

To even begin, I realize I need to request an oauth token. According to the documentation, I have to execute the following command:

# Base URL of TeamForge site.
site_url="https://teamforge.example.com"

# TeamForge authentication credentials.
username="foo"
password="bar"

# Requested scope (all)
scope="urn:ctf:services:ctf urn:ctf:services:svn urn:ctf:services:gerrit urn:ctf:services:soap60"

curl -d "grant_type=password&client_id=api-client&scope=$scope&username=$username&password=$password" $site_url/oauth/auth/token

Seems fairly straightforward. Knowing that curl is an alias for Invoke-WebRequest, I attempted to run the following in PowerShell:

$site="https://my.teamforge.site"
$user="myuser"
$pass="mypass"
$scope="urn:ctf:services:ctf"
curl "grant_type=password&client_id=api-client&scope=$scope&username=$user&password=$pass" -Uri $site/oauth/auth/token

What I got was an error:

Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'grant_type=password&client_id=api-client&scope=urn:ctf:services:ctf&username= rest of line redacted for obvious reasons

I took this to mean I fudged the syntax. I have no clue where to start taking this appart and plugging it into Invoke-WebRequest command. Like I said, this is my first time attempting this. My searches for answers thus far has not been helpful. I think I am asking the wrong questions.

How do I deconstruct this curl command so that I can convert it to something I can use in PowerShell?

0

There are 0 best solutions below