Powershell and Rest API Postmark



当我通过powershell发送请求以restapi postmarkapp时,我有这些错误

使用Metod Get

Invoke-RestMethod : Cannot send a content-body with this verb-type.

使用Metod Post

Server Error in '/' Application. The resource cannot be found. 
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.
Requested URL: /deliverystats

脚本

$Uri         = 'https://api.postmarkapp.com/deliverystats'
Invoke-RestMethod $Uri -Method Post -Headers @{'X-Postmark-Server-Token' =" Token" }  -ContentType "application/json" |

您提供的脚本未完成 - 它以 |结尾。执行请求之前需要有效的令牌,否则您将获得此错误:

Invoke-RestMethod : {"ErrorCode":10,"Message":"No Account or Server API tokens were supplied in the HTTP headers. Please add a header for either 
X-Postmark-Server-Token or X-Postmark-Account-Token."}

您的代码具有' Token',它是常数,对于X-Postmark-Server-TokenX-Postmark-Account-Token标头可能不是有效的值。您没有显示如何设置$Token,但可能应该是这样的:

$Token = 'xxxxxxxxxxxxx' #your account specific token
$uri = 'https://api.postmarkapp.com/deliverystats'

然后添加这样的标题(在Token之前使用$(:

Invoke-RestMethod $Uri -Method Get -Headers @{'X-Postmark-Server-Token' ="$Token" }  -ContentType "application/json" 

最新更新