Invoke-Web request

I have been using Powershell v4 for most AD tasks, but find I need to create a space in Jivex for each user as well. Another user turned me on to Postman which allowed me to get some practice with a REST api, but I can't seem to get over the hump in making a post actually work using Invoke-web request.

$user = 'me'
$pass = 'MyPW'

$pair = "$($user):$($pass)"

$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))

$basicAuthValue = "Basic $encodedCreds"

$Headers = @{Authorization = $basicAuthValue}


$parenturlspace = 'https://mysandbox.jiveon.com/api/core/v3/places'
# using the url v3/places/1001/places does not work



$jiveprivatespacename = "kt12test"
$jiveprivatespacedisplayname = "34567"
$jivetype = "space"
$jivebody = '{"Name" : $jiveprivatespacename , "displayname" : $jiveprivatespacedisplayname , "type" : $jivetype}'



Invoke-WebRequest -uri $parenturlspace  -headers $headers -ContentType: application/json -Method POST  -Body $jivebody

#leaving out -ContentType give a error: (415) Unsupported media type. 
#Error now is error: (400) Bad request - suspect it has to do with the -Body - tried multiple variation without success

August 19th, 2015 1:06pm

Your $jivebody string is surrounded by single quotes, so the variables inside cannot expand.
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 1:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics