em_event table additional_Info field is returning [object Object]

edwio
Mega Contributor

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]:

find_real_file.png

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'
     					}"
      }     
   ]
}
"@
1 ACCEPTED SOLUTION

edwio
Mega Contributor

Turns out,
My Structure was effecting the only the additional_info section in my JSON.

Fixed,
Currently working as it should be:

find_real_file.png

Thanks for the help.

View solution in original post

14 REPLIES 14

I thought you had to escape the embedded double-quotes?

Do you have some way you can check the result of the conversion to JSON? Maybe print out the $bodyJson, or, even better, send it to somewhere else that can record the JSON that is received. 

Wait - I just noticed something. You have double quotes around the braces after additional_info; is that keeping the data from additional_info from being converted to the appropriate object type before it is converted to JSON? 

Steve

edwio
Mega Contributor

Still Same Problem,
This is my payload:

 

{
  "additional_content" : "[object Object]"
}

robertgeen
Tera Guru

I know someone who did a powershell script to push events I'll see if I can get a copy of it and show you how he did the json for additional_info. Gimmie the morning and I'll see if I can get a hold of the person.

dvp
Mega Sage
Mega Sage

Can you try removing quotes for additional info

"additional_info":{  
							"u_mc_object_class":"$AsourceCreatedId",
							"u_mc_parameter":"$AmetricName",
							"u_mc_parameter_value":"$AmetricValue"
     					}

edwio
Mega Contributor

Still same problem,
This is my payload:

{
  "additional_content" : "[object Object]"
}