Event fields not populating when executing api post

brentvardy
Kilo Expert

Hi,   I'm very new to the community and to Service Now Event Management.   I'm building a Ruby script that will post events to my Service Now Event Management instance. So far I am successfully, at least it appears so, events.   The Events show up in my instance however none of the fields that I am passing through as the POST data are not getting populated in to the event.   The JSON response I receive on making the call does not include any errors.  

Here is an example of the event (hardcoded currently) in ruby:

snow_event = {

    record: [

  {

    source: 'dev-monitor',
    ci_type: 'cmdb_ci_apache_web_server',
    resource: 'disk',
    node: 'server01',
    metric_name: 'Free Disk Space',
    type: 'disk_check',
    severity: '2',
    description: 'DISK WARNING - free space: /var 8%'
    }

  ]

}

Once the event is created in Service Now none of these fields are populated.   FYI I am using the httparty GEM to make the REST call.

This is what the event looks like in the Service Now interface:

find_real_file.png

This is an example of the response from the call:

{

    "result": {

    "resolution_state": "New",

    "processing_sn_node": "",

    "description": "",

    "source": "",

    "sys_updated_on": "2017-05-24 09:00:05",

    "type": "",

    "ci_identifier": "",

    "sys_id": "ede3b6e3db36f600f33471910f96192f",

    "sys_updated_by": "!!REMOVED!!",

    "ci_type": "",

    "metric_name": "",

    "processing_notes": "",

    "sys_created_on": "2017-05-24 09:00:05",

    "sys_domain": {

    "link": "https://!!REMOVED!!.service-now.com/api/now/table/sys_user_group/global",

    "value": "global"

  },

    "state": "Ready",

    "message_key": "",

    "sys_created_by": "!!REMOVED!!",

    "time_of_event": "2017-05-24 09:00:05",

    "severity": "",

    "error_msg": "",

    "cmdb_ci": "",

    "resource": "",

    "sys_mod_count": "0",

    "classification": "0",

    "sys_tags": "",

    "bucket": "85",

    "node": "",

    "processed": "",

    "additional_info": "",

    "processing_duration": "",

    "event_class": ""

  }

}

Any help in getting past this would be much appreciated.

1 ACCEPTED SOLUTION

Tony,



Thanks for the Postman example, I've now managed to resolve my problem because of this.   Here is a working example in Ruby using the httparty GEM:



snow_payload = {


    source:   "dev-monitor",
    node:   "server02",
    ci_type:   "cmdb_ci_apache_web_server",
    type:   "Free Disk Space",
    resource:   "/var",
    severity:   "3",
    metric_name:   "disk_check",
    description:   "Disk warning - free space /var 8%"
}



snow_auth = {:username => SNOW_USER, :password => SNOW_PASS}



snow_options = {


    basic_auth: snow_auth,
    verify: false,
    verify_peer: false,
    headers: {


    'Accept' => 'application/json',
    'Content-Type' => 'application/json'
    },
    body: snow_payload.to_json


}



response = HTTParty.post(SNOW_URL, snow_options)


View solution in original post

14 REPLIES 14

prabh
Mega Expert

Pls try to put all the parameters name in inverted commas. Like see below, description is under inverted comma.


"{\"description\":\"123\"}"


Hi, I dd try this in my last test submission and I got the same behaviour.



Thanks


Brent


Hi Brent,



The following format works for sending a single event (from Postman) to the following endpoint (https://<instancename>.service-now.com/api/now/table/em_event):



{


  "source":"dev-monitor",


  "node":"server01",


  "ci_type":"cmdb_ci_apache_web_server",


  "type":"Free Disk Space",


  "resource":"/var",


  "severity":"2",


  "metric_name":"disk_check",


  "description":"Disk warning - free space /var 8%"


}



Whereas using your original event results in the same behaviour.



If you want to send multiple events then you'd use the event format below and send to the following endpoint (https://<instancename>.service-now.com/em_event.do?JSONv2&sysparm_action=insertMultiple):



{ "records": [


  {


  "source": "dev-monitor",


  "node": "server01",


  "ci_type":"cmdb_ci_apache_web_server",


  "type": "Free Disk Space",


  "resource": "/var",


  "severity": "2",


  "metric_name":"disk_check",


  "description": "Disk warning - free space /var 8%"


  },


  {


  "source": "dev-monitor",


  "node": "server01",


  "ci_type":"cmdb_ci_apache_web_server",


  "type": "Free Disk Space",


  "resource": "/var",


  "severity": "0",


  "metric_name":"disk_check",


  "description": "Disk OK - free space /var 80%"


  }


]


}



The formats for each endpoint type are different, so be sure to use the correct one.


Tony thanks for this.   I've just tested using Postman too and like you was able to successfully post an event.   Using the same json in my Ruby Script however is still failing.   I will do some more troubleshooting and post any findings.   Thanks.


Tony,



Thanks for the Postman example, I've now managed to resolve my problem because of this.   Here is a working example in Ruby using the httparty GEM:



snow_payload = {


    source:   "dev-monitor",
    node:   "server02",
    ci_type:   "cmdb_ci_apache_web_server",
    type:   "Free Disk Space",
    resource:   "/var",
    severity:   "3",
    metric_name:   "disk_check",
    description:   "Disk warning - free space /var 8%"
}



snow_auth = {:username => SNOW_USER, :password => SNOW_PASS}



snow_options = {


    basic_auth: snow_auth,
    verify: false,
    verify_peer: false,
    headers: {


    'Accept' => 'application/json',
    'Content-Type' => 'application/json'
    },
    body: snow_payload.to_json


}



response = HTTParty.post(SNOW_URL, snow_options)