- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2019 03:44 AM
We are using Rest API via PowerShell (Invoke-RestMethod),
In order to insert records in the event [em_event] table with a single call, using the web service API.
We successfully inserting events to the em_event table,
But the only problem is with the additional_info field.
For some reason,
The JSON structure of my PowerShell script,
Is causing the output of additional_info, to return as an Object and Not as JSON string.
And as a result,
Not showing the values in additional_info properly, but instead as [object Object]:
This is the JSON structure in my PowerShell script:
# Specify request body
$body = @"
{ "records":
[
{
"source":"MyClass",
"event_class":"$AtargetResourceType",
"resource":"$AtargetResourceType",
"node":"$AtargetResourceName",
"metric_name":"$Aname",
"type":"$AsignalType",
"severity":"$Aseverity",
"message_key":"$Aid",
"u_mc_object":"$AtargetResource",
"description":"$Adescription",
"additional_info":"{
'u_mc_object_class':'$AsourceCreatedId',
'u_mc_parameter':'$AmetricName',
'u_mc_parameter_value':'$AmetricValue'
}"
}
]
}
"@
Solved! Go to Solution.
- Labels:
-
Event Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2019 02:35 AM
Turns out,
My Structure was effecting the only the additional_info section in my JSON.
Fixed,
Currently working as it should be:
Thanks for the help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2019 04:00 AM
Hi,
use the solution provided to the thread below:
The issue here is that the event engine is expecting additional_info to be a JSON string, but it's being sent as an object instead.
If I have answered your question, please mark my response as correct and/or helpful.
Thank you very much
Cheers
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2019 04:05 AM
I already wrote the cause of my problem,
And also reviewed the link you wrote,
but I'm using PowerShell Not Perl.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2019 05:51 PM
The problem is the single quotes. Single quotes are not valid in JSON. Replace them with double quotes and you'll be good to go. I believe you can embed double quotes in a string by escaping them with a backtick character (`).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 04:28 AM
@SteveMac, at first i thought that this could be the reason. but event with double quotes i"m still getting the same resault: [object Object].
This is the full ServiceNow Section in my Script:
# Eg. User name="admin", Password="admin" for this code sample.
$user = "MyUser"
$pass = "MyPassword"
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
# Set proper headers for SNOW
$SNOWheaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$SNOWheaders.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$SNOWheaders.Add('Accept','application/json')
$SNOWheaders.Add('Content-Type','application/json')
# Specify endpoint uri
# SNOW URI
$uri = "https://servicenow-myinstance/api/global/em/jsonv2"
# Specify HTTP method
$method = "Post"
# Specify request body
$body = @"
{ "records":
[
{
"source":"MyClass",
"event_class":"$AtargetResourceType",
"resource":"$AtargetResourceType",
"node":"$AtargetResourceName",
"metric_name":"$Aname",
"type":"$AsignalType",
"severity":"$Aseverity",
"message_key":"$Aid",
"u_mc_object":"$AtargetResource",
"description":"$Adescription",
"additional_info":"{
"u_mc_object_class":"$AsourceCreatedId",
"u_mc_parameter":"$AmetricName",
"u_mc_parameter_value":"$AmetricValue"
}"
}
]
}
"@
$bodyJson = $body | ConvertTo-Json
# Send HTTP reques
$response = Invoke-RestMethod -Headers $SNOWheaders -Method $method -Uri $uri -Body $bodyJson -ContentType "application/json" -UseBasicParsing