JSON formatted reply - Need help with response information


i've got script interacts jira create , updates issues(tickets).  during interaction, jira sends response each time.  just values change each new issue.

{"id":"315199","key":"itim-20728","self":"http://ourjiratestserver:8180/rest/ap
i/2/issue/315199"}

the part of code see is:

$b64 = convertto-base64($username + ":" + $password);
$auth = "basic " + $b64;
  
$webrequest = [system.net.webrequest]::create($target+"/rest/api/2/issue/")
$webrequest.contenttype = "application/json"
$bodystr = [system.text.encoding]::utf8.getbytes($body)
$webrequest.contentlength = $bodystr.length
$webrequest.servicepoint.expect100continue = $false
$webrequest.headers.add("authorization", $auth);
$webrequest.preauthenticate = $true
$webrequest.method = "post"
$requeststream = $webrequest.getrequeststream()
$requeststream.write($bodystr, 0, $bodystr.length)
$requeststream.close()
[system.net.webresponse] $resp = $webrequest.getresponse()
  
$rs = $resp.getresponsestream()
[system.io.streamreader] $sr = new-object system.io.streamreader -argumentlist $rs
[string] $results = $sr.readtoend()
write-output $results
}
  
catch [system.net.webexception]{
        if ($_.exception -ne $null -and $_.exception.response -ne $null) {
            $errorresult = $_.exception.response.getresponsestream()
            $errortext = (new-object system.io.streamreader($errorresult)).readtoend()
            write-warning "the remote server response: $errortext"
            write-output $_.exception.response.statuscode
        } else {
            throw $_
        }
    }

how can take response , pull url path out of , place variable? 

thanks

just convert it:

ps d:\scripts> $a = '{"id":"315199","key":"itim-20728","self":"http://ourjiratestserver:8180/rest/api/2/issue/315199"}' ps d:\scripts> ($a | convertfrom-json).self http://ourjiratestserver:8180/rest/api/2/issue/315199
easier use "invoke-webrequest" of work you.


\_(ツ)_/





Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file