API – Execute an Action Script

action – script

An Action Script can be evaluated against a specific record or, if the content of the script allows, without specifying a record first.

Action Script on a Specific Record

Use the action script and specify a record. The script contained in script will be evaluated against the record.

Sample Request

{ "account": *** your account id ***, "apikey": "*** your api key ***", "action": "script", "recordurl": "person/12345", "script": " IF LastName="Smith" Email="j.smith@smithmotors.com" END " }

Sample Response

{ "success": true }

Action Script not on a Specific Record

Sample Request

{ "account": *** your account id ***, "apikey": "*** your api key ***", "action": "script", "script": " ADD RECORD Person FirstName="Ben" LastName="Kenobi" END " }

Sample Response

{ "success": true }

Returning Variables From an Action Script

It is possible to set variable values during evaluation of an ActionScript. The values of these variables are returned in data. All variable names are returned in lower-case – variable names are not case-sensitive within scripts.

Note that this is an extremely flexible way to calculate and extract information of any complexity from a PYXI application. You can use the full power of the scripting language to evaluate multiple records, perform calculations etc and have all the variable values returned through this API call.

Sample Request

{ "account": *** your account id ***, "apikey": "*** your api key ***", "action": "script", "script": " IF true SET vResponse = "abcd" END " }

Sample Response

{ "success": true, "data": { "vresponse": "abcd" } }

Action Script with Data Provided in call

Similar to templates, Action Scripts can act on data passed in the API call. This data overrides what would otherwise be evaluated using the variable name (if anything).

Sample Request

{ "account": *** your account id ***, "apikey": "*** your api key ***", "action": "script", "script": " ADD RECORD Person FirstName=vFirstName LastName=vLastName END ", "data": { "vFirstName": "Leia", "vLastName": "Organa" } }

Sample Response

{ "success": true }

Note that this is, of course, an over-simplified example to demonstrate basic syntax. In practice, if you just needed to add a single record like this, you would use the Add Record API call instead so you get the record id back in the response.

Get Started