0

when I send a request through powershell to rest api Postmarkapp I have these errors

When use metod get

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

When use 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

Script

$Uri         = 'https://api.postmarkapp.com/deliverystats'
Invoke-RestMethod $Uri -Method Post -Headers @{'X-Postmark-Server-Token' =" Token" }  -ContentType "application/json" |
TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56
  • Have you tried to test your requests with `curl` as specified [here](https://postmarkapp.com/developer/api/bounce-api)? – montonero May 08 '19 at 22:41

1 Answers1

0

The script you provided wasn't complete - it ends with a |. A valid token is required before executing a request or you'll get this error:

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."}

Your code had ' Token', which is a constant and is probably not a valid value for the X-Postmark-Server-Token or X-Postmark-Account-Token header. You didn't show how $Token was set, but it probably should have been something like this:

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

Then add the headers like this (with a $ before Token):

Invoke-RestMethod $Uri -Method Get -Headers @{'X-Postmark-Server-Token' ="$Token" }  -ContentType "application/json" 
Rich Moss
  • 2,195
  • 1
  • 13
  • 18