Skip to content

Instantly share code, notes, and snippets.

@KevM
Forked from gsherman/CreateCase.ps1
Created March 16, 2012 21:43
Show Gist options
  • Save KevM/2052923 to your computer and use it in GitHub Desktop.
Save KevM/2052923 to your computer and use it in GitHub Desktop.
PowerShell script that creates a case using a webservice based on the Dovetail SDK
## Dependencies:
## ConvertFrom-JSON which is available at: http://powershelljson.codeplex.com/
. .\ConvertFrom-JSON.ps1
$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)
$result = ConvertFrom-JSON $json
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