What's wrong here . . .

What's wrong here . . .

I'm trying to get my scripts updated to API v3 in order to do the upgrade to the latest version of Service Desk.  I am completely stuck and I do not understand why.  I have quite a few API v1 scripts that work just fine.  Yes, I understand there is a lot of difference, but I cannot make even the simplest of scripts work with v3.

Here is one example of an incredibly simple script that works fine in v1 and absolutely refuses to work in v3.  The v1 version of this script runs as a custom trigger and picks up the Request ID from the JSON.


  1.  $appdata = @"
  2. {  
  3.     "request": {
  4.         "mode": {
  5.             "name": "Voice Mail"
  6.         }
  7.     }
  8. }
  9. "@


  10. $TechKey = "68F75C29-4754-4A28-BDAB-2516D86A05C7"
  11. $Method = "PUT"
  12. $SDurl = "http://localhost/api/v3/requests/311921"

  13. $params = @{input_data=$appdata;format='json'}
  14. $Header = @{TECHNICIAN_KEY=$TechKey}

  15. $result = Invoke-RestMethod -Method $Method -Uri $SDurl -Body $params -Headers $Header
The result of the script is:
  1. Invoke-RestMethod : {"response_status":{"status_code":4000,"messages":[{"status_code":4004,"type":"failed","message":"Internal Error"}],"status":"failed"}}
  2. At line:27 char:11
  3. + $result = Invoke-RestMethod -Method $Method -Uri $SDurl -Body $params -Headers $ ...
  4. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5.     + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
  6.     + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Using the API documentation locally, everything appears to be in order:



When I check the request after using the API doc, the mode changes as expected.

Clearly I'm doing something wrong, but I cannot spot it.



                  New to ADSelfService Plus?