Javascript "Object" object in js callouts

Hi Apigeeks,

I normal Javascript we have a parent to all the objects in javascript i.e. "Object". I was trying to use the same in JS callouts to get the list of properties of a JSON object in apigee but got an error saying object.getownpropertynames is not defined.

Is it not possible to use normal "Object" class in JS callouts? Any idea why not or any future plans on adding this in JS callouts.

Solved Solved
1 4 773
1 ACCEPTED SOLUTION

The runtime for JS callouts in Apigee Edge is Rhino. It's also a restricted version, to prevent creation of arbitrary Java objects within the JS script, and also to prevent invocation of arbitrary methods.

So getownpropertynames is out.

You can do what you want with this:

Object.keys(obj).forEach(function(propertyName) { 
  // propertyName is one key of the given object
}); 

Does this solve your problem?

View solution in original post

4 REPLIES 4

The runtime for JS callouts in Apigee Edge is Rhino. It's also a restricted version, to prevent creation of arbitrary Java objects within the JS script, and also to prevent invocation of arbitrary methods.

So getownpropertynames is out.

You can do what you want with this:

Object.keys(obj).forEach(function(propertyName) { 
  // propertyName is one key of the given object
}); 

Does this solve your problem?

Thanks, @Dino, finally I ended up using the same method. Do we have any reference documentation stating what methods and features have been restricted in Rhino, or which version of Rhino is being used in apigee edge as of the latest release 4.17.0.1?

This page says OPDK 4.17.01 uses Rhino 1.7.7.1 .

I do not know of a format list of things you cannot do in JS callouts. I know that you cannot do:

  • ES6 things
  • extension of the Object.prototype
  • instantiation of arbitrary Java classes

Good luck!

Thanks a lot @Dino, this clears most of the doubts.