Abhiram Diddigi home

Service Now is not afraid to POST some REST

This is a supplement to this post Service Now is not afraid to get some Rest

I recently came across a tool that can only understand REST. In this post we will be Sending a POST call over HTTP using Service Now’s java Packages. You can see another method of setting parameters at this URL on community. But in this blog post we will be POSTing an XML

You can test it out in Scripts- Background

var xml  = Packages.java.lang.String();
gs.log('Started'+current.number);

/** Creating the XML **/


xml = " "+
					""+
					      "provisoning"+
					      "Abhiram"+
					      "Mysql database needed for Devlopment Env"+
					      "Mysql database needed for Devlopment Env "+     
					     " 
"+ ""+ "cloudProvider"+ "private"+ " "+ ""+ "serviceOffering"+ "small"+ ""+ ""+ "quantity"+ "1"+ ""+ " "+ "platform"+ "linux"+ ""+ ""+ "os"+ "Redhat"+ " "+ ""+ "osVersion"+ "Redhat6.2"+ ""+ ""+ "softwareversion"+ "mysql-5.1.47-4.el6"+ ""+ ""+ "taskid"+ ""+current.number+""+ ""+ "
"+ "
";

/**
Setting the String Request Entity
**/
				
var sre = new Packages.org.apache.commons.httpclient.methods.StringRequestEntity(xml);
var client = new Packages.org.apache.commons.httpclient.HttpClient();
var post = new Packages.org.apache.commons.httpclient.methods.PostMethod("http://321.566.677.155:8080/Prov/action/doAction.xml");
gs.log("XML"+xml);


post.setRequestEntity(sre); 
            post.setRequestHeader("Content-type","application/xml"); 
                 
            var result = client.executeMethod(post);
            gs.log("Response status code: " + result);         
            gs.log(post.getResponseBodyAsString());
gs.log('end');