Java API code to create new incident

chitrat
Tera Contributor

Hi All,

Am new to ServiceNow and in the process valuating it.

Here my requirement is I need to create a new incident with the Java code.

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

Thanks in advance

Chitra

1 ACCEPTED SOLUTION

tony_barratt
ServiceNow Employee

Hi Chitra,



There is example java code here:


Table API Java Examples - ServiceNow Wiki



3.2 POST


..



Does that help answer your question?



Best Regards



Tony


View solution in original post

24 REPLIES 24

tony_barratt
ServiceNow Employee

Hi Chitra,



There is example java code here:


Table API Java Examples - ServiceNow Wiki



3.2 POST


..



Does that help answer your question?



Best Regards



Tony


Hi Tony,



Its close enough.This is what I want.



I tried to run the code from my eclipse and am getting the below error


"


Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE


      at org.apache.http.impl.conn.HttpClientConnectionOperator.<init>(HttpClientConnectionOperator.java:74)


      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:151)


      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138)


      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114)


      at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)


      at chitra.iopex.com.GetAction.postRequest(GetAction.java:34)


      at chitra.iopex.com.GetAction.main(GetAction.java:22)



"



Searched for this error but no solution is working.


Any idea ?



Thanks


Chitra


tony_barratt
ServiceNow Employee

Hi Chitra,


Good to hear it is useful for you.


Have you updated this line to point to the actual URL of your instance?



HttpMethod method = new PutMethod(


  "https://instance.servicenow.com/api/now/table/incident/8190e877d7031100261253b2b252033e");



Best Regards



Tony


chitrat
Tera Contributor

HTTPClient jar file is the issue.



Changed the jar file version from httpclient 4.3 to 4.3.3 and its working now.



Thanks Tony