0

我需要使用 PowerShell 脚本来创建 Zendesk 票证。但我不断从 API 收到以下错误:

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();

提前感谢您的任何见解,因为我大部分时间都在用头撞墙。

4

1 回答 1

0

您会发现Powershell 3Invoke-RestMethod很有用,您不必担心创建整个通话的有效性,只需担心内容部分。也尝试使用方括号:

[{"ticket":{"subject":"My printer is on fire!", "comment": { "body": "The smoke is very colorful." }}}]
于 2014-02-07T10:12:43.593 回答