How to create/update/close incidents using Java rest API

Ikenahim
Kilo Explorer

Hello guys,

I'm new to servicenow, and I read the doc but I got lost. not what I used to.

Here my requirement is I need to create a new incident with the Java code. and updated/close it

while creating incident I want to assign it to a user/group of users depends on my need. 

Can anyone help me with the API Java code to create new incident on ServiceNow?

  I have checked this link https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/integrate/inbound-rest/reference/r_TableAPIJavaExamples.html?title=Table_API_Java_Examples#gsc.tab=0 but it has no simple in JAVA!

creating API request POST/DELETE/PUT is not an issue for me, I'm familiar with it. just want to know the URL and required fields for my requirements. 

Any help?

Thanks in advance

Ibrahim

4 REPLIES 4

vkachineni
Kilo Sage
Kilo Sage

Take a look at 

https://community.servicenow.com/community?id=community_question&sys_id=a7c78b9bdba9e7404abd5583ca961950

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Ikenahim
Kilo Explorer

I don't have issue with setting connection with ServiceNow using API. I want to know which field are required to create an incident / also how to update . close and reopen an incident?

 

Thank you

Chandra Rawat
Kilo Contributor

Hi,

 

Please use below code:

 

Hi - Following is done on a developer instance OOB

 

 

 

PUT https://devXXXX.service-now.com/api/now/table/incident/2eed78cd4f763200eacf2ed18110c143

 

Parameter in BOLD is sys_id of the ticket being closed

 

 

 

Payload - {"close_code":"Closed/Resolved By Caller","state":"7","caller_id":"6816f79cc0a8016401c5a33be04be331","close_notes":"Closed by API"}

 

caller_id in bold is the sys_id for the user closing the ticket.

 

 

 

These are the minimum field required to close.

Please mark helpful if it works for you.

 

 

Ikenahim
Kilo Explorer

I figure out how to get the incident using sys_id, as I understood:

-state = 1 means its new

-state = 2 means reopened incident

-state = 3 means closed

-state = 7 means resolved 

 

is this correct ?

 

is there way to know if an incident was open and assigned to someone to resolve it ?

how to differentiate between new incident and open incident ?

 

Thank you