2014-02-07 21 views
0

我需要使用PowerShell腳本來創建Zendesk票證。但我一直從API收到以下錯誤回:從PowerShell腳本創建Zendesk票證失敗:(422)無法處理的實體

The remote server returned an error: (422) Unprocessable Entity. 

下面是腳本:

$username="username"; 
$password="password"; 

$request = [System.Net.WebRequest]::Create('https://domain.zendesk.com/api/v2/tickets.json'); 
$request.Method = "POST"; 
$request.ContentType = "Content-Type: application/json"; 


$request.Credentials = New-Object System.Net.NetworkCredential($username, $password) 


$bytes = [System.Text.Encoding]::ASCII.GetBytes('{"ticket":{"subject":"My printer is on fire!", "comment": { "body": "The smoke is very colorful." }}}'); 

$requestStream = $request.GetRequestStream(); 
$requestStream.Write($bytes, 0, $bytes.Length); 
$requestStream.Close(); 

$response = $request.GetResponse(); 

預先感謝任何見解,因爲我大部分時間我每天敲我的頭靠牆。

回答

0

Powershell 3有Invoke-RestMethod你會發現有用的,你不必擔心創建一個有效的整個電話,只是內容的一部分。也請試用方括號:

[{"ticket":{"subject":"My printer is on fire!", "comment": { "body": "The smoke is very colorful." }}}] 
相關問題