how to use a CartJS for scripted rest api.

Rahul Tiwari2
Tera Contributor

when i am trying to apply a CartJS in scripted rest api  while testing through a postman i am getting

error - "

java.lang.ClassCastException: class org.mozilla.javascript.NativeJavaObject cannot be cast to class java.lang.String (org.mozilla.javascript.NativeJavaObject is in unnamed module of loader com.snc.orbit.container.tomcat8.Tomcat8$OrbitTomcat8ClassLoader @141b2ec; java.lang.String is in module java.base of loader 'bootstrap')"

 

2 REPLIES 2

Alok2
Tera Contributor

Hi Rahul,

 

I had done the same thing and it worked for me. I created a scripted rest API "cartapitest" and then a POST resource called "createRequest",  then from Postman I passed the URL "https://xxxxxx.service-now.com/api/760201/cartapitest". I used Basic Auth, in the header I passed a value which I used in the scripted rest API script using the method "request.getHeader()" which I then passed in my CartAPI script.

var cart = new sn_sc.CartJS();
var request1 = {
'sysparm_id': '039c516237b1300054b6a3549dbe5dfc',
'sysparm_quantity': '1',
'variables': {
'abc': request.getHeader('short_description')

}
};
var cartDetails = cart.orderNow(request1);

This creates the request correctly and maps the variable too.
gs.info(cartDetails);

Rahul77
Tera Contributor

how to use a variable set using cartjs.