Resolution for JSON parsing error “The given key was not present in the dictionary.”

Server Man

Well-Known Member
Joined
May 17, 2015
Windows 10
Windows 10
Chrome 72.0.3626.121
Chrome 72.0.3626.121
Thread starter #1
While leveraging SCOM REST API, if you get the error message “The given key was not present in the dictionary.“ then it means that the request body is not being parsed correctly. For resolving this error, make sure that the Content-Type header is set to “application/json” and JSON.stringify() is called on the data value to convert it into string.

Below is a sample snippet of the script with the usage of Content-Type header and JSON.stringify to resolve such errors:

window.onload = function () {
$.ajax({
url: "/OperationsManager/data/performance",
type: "POST",
headers: {
"Content-Type": "application/json"
},
data: JSON.stringify({
"duration":1440,
"id":"721BEA34-B0E4-DC97-5169-52808F731A6B",
"performanceCounters":[
{
"objectname":"Health Service",
"countername":"agent processor utilization",
"instancename":""
}
],
}),

Continue reading...