Quick Test Execute Code Script Command

Prev Next

Use Quick Run to execute JavaScript code services, allowing the player to communicate with other systems via APIs.

For example - you can trigger a request to pull current currency exchange rates, as shown below.

You can use the following functions - 

  • httpGet
    Use the httpGet function to generate an HTTP GET request.
    var Results = httpGet(URL)
     

  • httpPost
    Use the httpPost function to generate an HTTP POST request.
    var Results = httpPost(URL, POST_DATA)
     

  • panayaVars
    You can read or update any Panaya parameter values within the code using the syntax panayaVars.parameterName.
    To do this, use the parameters defined in previous steps; see the example below.

    Important!

    When utilizing panayaVars in Javascript, use the exact capitalization case for the parameter names.


Example - Pull Exchange Rate Value

var currencyJsonResult = httpGet('https://api.frankfurter.app/latest?from=USD&to=GBP'); //Receive the currency exchange rate value

      //Example of result:  {"amount":1.0,"base":"USD","date":"2024-06-25","rates":{"GBP":0.78836}}
 

var jsobObj = JSON.parse(currencyJsonResult);

var rateGbpToUsd = jsobObj.rates.GBP; //Extract the GBP to USD exchange rate value from results using JS parser

if (rateGbpToUsd > 0) //If the rate is larger than 0, then 

{

    panayaVars.productPrice = rateGbpToUsd*panayaVars.productPrice; //Populate the <productPrice> parameter. 
//productPrice is a predefined Panaya parameter

}