Post API - non-required data not populating

justinhuggi
Kilo Contributor

I am using the SCADA system, Inductive Automation Ignition, 8.1.  I am able to successfully create an incident with the script below from the Ignition platform.  The problem I am having is getting non-required fields to populate.  After running this script, the short_description and caller_id work perfect(these are the only two required fields), but the description will not populate.  I have also tried some other fields such as comments, notes.  Any idea what would prevent the non-required fields from populating into the incident that is created?

 

client = system.net.httpClient(cookie_policy="ACCEPT_NONE")

url = "https://mysite.service-now.com/api/now/table/incident"

header = {
	"Content-Type":"application/json",
	"Accept":"application/json",
}

params = {
	"short_description": "From Ignition Console",
	"caller_id": "My Name",
	"description": "Device is having a problem",
}

post = client.post(
	url, 
	data=params, 
	headers=header,
	username="myusername",
	password="mypassword"
)

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @justinhuggi ,

ChatGPT said:

You're on the right path, and it's great that your script can already create an incident with short_description and caller_id. The issue you're facing with fields like description not populating usually boils down to data formatting, field naming, or permissions.

1. Use JSON for the data payload (not form-encoded)

Right now, you're passing data=params, which may be interpreted as form data. For ServiceNow's REST API, it's best to convert the params dictionary to a JSON string before posting it.

 

Change this line:

data=params

To this:

data=system.util.jsonEncode(params)

 

This ensures your request body is properly sent as JSON, which is required by the Content-Type: application/json header.

 

Make sure you’re using the correct API field names. For example:

  • description is valid (it maps to the description field in the incident table).

  • comments and work_notes are also valid, but they might be restricted via ACLs.

When using "caller_id": "My Name", it only works if the name exactly matches a ServiceNow user display name. It's better to use the sys_id of the caller.

"caller_id": "b7a9c3bc1b5f4410fa53bfa0b24c4bd1"      //example sys_id of user

 

Sometimes, fields like description, work_notes, and comments are protected by ACLs that block write access via the API — especially for non-admin users. Make sure your integration user has:

  • itil role (minimum to create incidents),

  • Or proper write ACLs for those fields.

 

Updated working script:

client = system.net.httpClient(cookie_policy="ACCEPT_NONE")

url = "https://mysite.service-now.com/api/now/table/incident"

header = {
	"Content-Type":"application/json",
	"Accept":"application/json",
}

params = {
	"short_description": "From Ignition Console",
	"caller_id": "My Name",  # Preferably use sys_id here
	"description": "Device is having a problem",
}

post = client.post(
	url, 
	data=system.util.jsonEncode(params), 
	headers=header,
	username="myusername",
	password="mypassword"
)

 

View solution in original post

3 REPLIES 3

justinhuggi
Kilo Contributor

This is the link to the Ignition documentation, if that is helpful at all. 

system-net-httpClient 

Community Alums
Not applicable

Hi @justinhuggi ,

ChatGPT said:

You're on the right path, and it's great that your script can already create an incident with short_description and caller_id. The issue you're facing with fields like description not populating usually boils down to data formatting, field naming, or permissions.

1. Use JSON for the data payload (not form-encoded)

Right now, you're passing data=params, which may be interpreted as form data. For ServiceNow's REST API, it's best to convert the params dictionary to a JSON string before posting it.

 

Change this line:

data=params

To this:

data=system.util.jsonEncode(params)

 

This ensures your request body is properly sent as JSON, which is required by the Content-Type: application/json header.

 

Make sure you’re using the correct API field names. For example:

  • description is valid (it maps to the description field in the incident table).

  • comments and work_notes are also valid, but they might be restricted via ACLs.

When using "caller_id": "My Name", it only works if the name exactly matches a ServiceNow user display name. It's better to use the sys_id of the caller.

"caller_id": "b7a9c3bc1b5f4410fa53bfa0b24c4bd1"      //example sys_id of user

 

Sometimes, fields like description, work_notes, and comments are protected by ACLs that block write access via the API — especially for non-admin users. Make sure your integration user has:

  • itil role (minimum to create incidents),

  • Or proper write ACLs for those fields.

 

Updated working script:

client = system.net.httpClient(cookie_policy="ACCEPT_NONE")

url = "https://mysite.service-now.com/api/now/table/incident"

header = {
	"Content-Type":"application/json",
	"Accept":"application/json",
}

params = {
	"short_description": "From Ignition Console",
	"caller_id": "My Name",  # Preferably use sys_id here
	"description": "Device is having a problem",
}

post = client.post(
	url, 
	data=system.util.jsonEncode(params), 
	headers=header,
	username="myusername",
	password="mypassword"
)

 

I added the itil role to web_service_admin and seems to work perfectly now!  

 

Thanks for the help!