How to use the Execute Code command?

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 HTTP GET request

    var Results = httpGet(URL)
     
  • httpPost
    Use the httpPost function to generate 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 parameters defined in previous steps, See example below. 


Example - Pull Exchange Rate Value

1
2
3
4
5
6
7
8
9
var currencyJsonResult = httpGet('http://api.fixer.io/latest?base=USD&symbols=GBP');
//Example of result: {"base":"USD","date":"2017-09-26","rates":{"GBP":0.74468}}
var jsobObj = JSON.parse(currencyJsonResult);
var rateGbpToUsd = jsobObj.rates.GBP;
if (rateGbpToUsd > 0)
{
    httpPost("http://posttestserver.com/post.php","Price="+rateGbpToUsd*panayaVars.productPrice);
    panayaVars.productPrice = rateGbpToUsd*panayaVars.productPrice;
}

Line 1 - Receive the currency exchange rate value

Line 3-4 - Extract the GBP to USD exchange rate value from results using JS parser

Line 5 - If the rate is larger than 0, then 

Line 7 - Posting the exchange rate externally

Line 8 - Populate the <productPrice> parameter