- 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-24-2019 03:36 PM
Edwio,
I think what you need to do is use the following to do your json:
If you do something like this:
#'additional_info'="$($object | ConvertTo-Json)"
$object would contain all the json content it should convert it properly since apparently it doesn't take it in Powershell as JSON it takes it as an object. I think this should fix it if you put all your content into a variable and then use ConvertTo-Json on it it should fix things for you. Let me know if this works (I'm still working on getting a copy of the script that was used). Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2019 10:32 PM
can you please elaborate on your answer? i'm not sure that i understand it,
Because i'm already converting $body to JSON string:
$bodyJson = $body | ConvertTo-Json
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2019 02:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 08:36 PM
I don't see what was wrong with your JSON structure. I've got the same issue and completely stumped why it's ending up as [object object]
So...what did you change to make it work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 08:59 PM
I found your thread over in StackOverflow as well with a useful solution.