HelpSpot Help Desk Software | HelpSpot Blog | HelpSpot Support

Posting to private APIs from PowerShell


I’m struggling to post information to HelpSpot through the API using PowerShell. GET requests work but POSTs do not. This does not seem like a credential or language issue since I’m getting a response from the server.

### Get the request
$getUri = $uri + "method=private.request.get&xRequest=$requestId"
Invoke-RestMethod -Uri $getUri -Method Get -Credential $credential
# https://.../api/index.php?output=json&method=private.request.get&xRequest=30579
# returns successfully

I’ve tried formatting the body different ways, passing $requestId as string and int, and adding a ContentType to the request but cannot get it to work.

### Update the request
$postUri = $uri + 'method=private.request.update'
# https://.../api/index.php?output=json&method=private.request.update

$body = @{
    xRequest = $requestId
    tNote = $Note
$json = ConvertTo-Json $body
# {
#    "xRequest":  30579,
#    "tNote":  "this is an update"
# }

Invoke-RestMethod -Uri $postUri -Method Post -Credential $credential -Body $json
# Response:
' [23,1: Invoke-RestMethod] {"error":[{"id":101,"description":"Required parameter xRequest not supplied"},{"id":103,"description":"Val id request ID required"}]}'



Hi there. I don’t profess to be a powershell expert, but here’s what worked in my testing:

$user = "someusername"
$pass= "somepassword"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd)
Invoke-WebRequest -Uri http://localhost/helpspot/api/index.php?method=private.request.update -Method POST -Body $postParams -Credential $credential```


You are right. Not sure why I didn’t bump into that at least by accident. PowerShell serializes the hashtable on it’s own so there is no need for ConvertTo-Json.



Sweet, glad that got things working.