OPScripts triggered via Web APIs can also accept input entered in the request body. Unlike URL input, reading a request body does not require any modification to the 'Main()' function of OPScript. Obtaining the request body can be simply done using the following function
The example below returns a JSON object of the request body:
If the request body contains a JSON input, the JSON input can be converted into an object using the '.ToObject(definition)' function. The function requires one to specify a definition of the expected JSON object.
OPScript JSON definition tells OPScript how to read a JSON string and convert it to an Object. For those familiar with C#, JSON definitions are C# dynamic objects.
Defining a definition is usually done by self analyzing a JSON string and determining the nesting of propeties and whether each property is an array or single variable. If a property is an array, it must be defined with "new".
Take example the following JSON property
JSON Definitions are also used when reading OPScript Parameters via the OP.GetParameter