Add note with Powershell and API V3

Add note with Powershell and API V3

Hi,

We have existing scripts that utilizes API V2 to add notes to requests, and it works fine.

Now we want to update those scripts to use API V3, and I can't get it working. We are running SD+ 9411 by the way.

Can anyone provide a working example, or point out what I am doing wroing?

Thanks in advance,
Rasmus

This is what I have coded, which returns a status code of 4007 (failed):

# GLOBAL VARIABLES
$sdphost = " http://servicedesk-url/"
$techkey = "XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX"

# CREATE NOTE
Function Add-SDNote{
# Add CmdletBinding adds common parameters like -verbose and -debug
[CmdletBinding()]

# Define parameters passed with the function call
param(
[Parameter(Mandatory=$True)]
[int]$RequestID,
[Parameter(Mandatory=$True)]
[string]$Note
)

# Define local function variables
$url = $sdphost + "api/v3/request/" + $RequestID + "/notes"
$method = "PUT"
$header = @{TECHNICIAN_KEY=$techkey}

$input = @"
{
"request_note": {
"mark_first_response": false,
"notify_technician": false,
"show_to_requester": false,
"description": "$Note"
}
}
"@

# Put them all together in the JSON format SD likes
$params = @{INPUT_DATA=$input;format='json'}

# Post the note to the SD request
Invoke-RestMethod -Method PUT -Uri $url -Headers $header -Body $params -ContentType "application/vnd.manageengine.sdp.v3+json"

}

Add-SDNote -RequestID 14883 -Note "Test note through API V3."

                  New to ADSelfService Plus?