我需要使用一个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();
事先谢谢你的见解,因为我一天的大部分时间都在把头撞在墙上。
发布于 2014-02-07 10:12:43
Powershell 3有Invoke-RestMethod
,您会发现它很有用,您不必担心创建整个调用的有效性,只需创建内容部分。还可以尝试使用方括号:
[{"ticket":{"subject":"My printer is on fire!", "comment": { "body": "The smoke is very colorful." }}}]
https://stackoverflow.com/questions/21616800
复制相似问题