Created
March 15, 2012 21:46
-
-
Save gsherman/2047194 to your computer and use it in GitHub Desktop.
PowerShell script that creates a case using a webservice based on the Dovetail SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$URL = "http://localhost/webservices/api/cases/create/" | |
$authToken = "7B118ABB-43C0-4215-A1D4-D536843728B5"; | |
$propertyCode = "0595"; | |
$summary = "This is the case title"; | |
$notes = "These are case notes."; | |
$alternateCaseId = "12345"; | |
$acceptHeader = "application/json"; | |
#$acceptHeader = "text/html"; | |
$postData=New-Object System.Collections.Specialized.NameValueCollection | |
$postData.Add('authToken',$authToken) | |
$postData.Add('propertyCode',$propertyCode) | |
$postData.Add('summary',$summary ) | |
$postData.Add('notes',$notes) | |
$postData.Add('AlternateCaseID',$alternateCaseId) | |
$webClient = new-object "System.Net.WebClient" | |
$webClient.Headers.Add("Accept", $acceptHeader); | |
try { | |
$response = $webClient.UploadValues($URL,$postData); | |
} | |
catch [Net.WebException] { | |
$e = $_.Exception | |
$response = $e.Response; | |
$requestStream = $response.GetResponseStream() | |
$readStream = new-object System.IO.StreamReader $requestStream | |
new-variable db | |
$db = $readStream.ReadToEnd() | |
$readStream.Close() | |
$response.Close() | |
$db; | |
$httpStatusCode = [int]$response.StatusCode | |
Write-Host | |
Write-Host HTTP Status: $httpStatusCode $response.StatusCode | |
exit; | |
} | |
$json = [System.Text.Encoding]::ASCII.GetString($response) | |
add-type -assembly system.web.extensions | |
$jsSerializer = New-Object System.Web.Script.Serialization.JavaScriptSerializer | |
$jsonResult = $jsSerializer.DeserializeObject( $json ) | |
$result = New-Object PSObject -Property @{ Id = $jsonResult["Id"] } | |
Write-Host Successfully Created Case $result.Id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment