How to return objects from plugins (SSA, CSA, Element Update & Element Workflow Actions)

Hi @lottemint.md I have been using your module and it’s working great. Only issue I’ve found Is I am having trouble getting a response when using arrays of objects.

I am using this simple code to return the data.

var body = JSON.parse(response.body);

const {convert} = require('json-to-bubble-object');
    
        
let returnlist = []
returnlist.push(convert(body))
                
    return {
        "result": returnlist,
    
    }
}

(the response.body is simply the JSON response from the API). For the following response which is a singular objects such as


{"symbol":"BTCUSDT","priceChange":"181.33000000","priceChangePercent":"0.499","weightedAvgPrice":"36644.71400220","prevClosePrice":"36366.40000000","lastPrice":"36547.73000000","lastQty":"0.08275600","bidPrice":"36546.00000000","bidQty":"0.07223800","askPrice":"36551.16000000","askQty":"0.05581300","openPrice":"36366.40000000","highPrice":"37489.80000000","lowPrice":"35533.92000000","volume":"3393.15320200","quoteVolume":"124341128.65294207","openTime":1643281515271,"closeTime":1643367915271,"firstId":2418729,"lastId":2506758,"count":88030}

This code is returning perfectly and I am getting responses as expected. When I run the same code on an array of objects such as the following, I get a null response. Do you know why this is?

[{"symbol":"BNBBUSD","priceChange":"-170.00000000","priceChangePercent":"-45.946","weightedAvgPrice":"420.48349812","prevClosePrice":"600.00000000","lastPrice":"200.00000000","lastQty":"2.00000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"350.00000000","askQty":"50.00000000","openPrice":"370.00000000","highPrice":"532.00000000","lowPrice":"200.00000000","volume":"71.81000000","quoteVolume":"30194.92000000","openTime":1643276491573,"closeTime":1643362891573,"firstId":1733,"lastId":1769,"count":37},{"symbol":"BTCBUSD","priceChange":"482142.00000000","priceChangePercent":"93.103","weightedAvgPrice":"613856.95824122","prevClosePrice":"1000000.00000000","lastPrice":"999999.00000000","lastQty":"0.00010000","bidPrice":"250000.00000000","bidQty":"0.00009000","askPrice":"999999.00000000","askQty":"0.00552000","openPrice":"517857.00000000","highPrice":"1000000.00000000","lowPrice":"250000.00000000","volume":"0.03700300","quoteVolume":"22714.54902580","openTime":1643281294370,"closeTime":1643367694370,"firstId":2153,"lastId":2340,"count":188},{"symbol":"ETHBUSD","priceChange":"-45973.11000000","priceChangePercent":"-94.884","weightedAvgPrice":"2984.76894256","prevClosePrice":"25039.43000000","lastPrice":"2479.00000000","lastQty":"0.21779000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"2479.00000000","askQty":"0.15333000","openPrice":"48452.11000000","highPrice":"48452.11000000","lowPrice":"1982.76000000","volume":"4.38794000","quoteVolume":"13096.98703380","openTime":1643278093979,"closeTime":1643364493979,"firstId":7456,"lastId":7550,"count":95},{"symbol":"LTCBUSD","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"61.00000000","prevClosePrice":"60.00000000","lastPrice":"61.00000000","lastQty":"1.00000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"61.00000000","highPrice":"61.00000000","lowPrice":"61.00000000","volume":"1.00000000","quoteVolume":"61.00000000","openTime":1642790849411,"closeTime":1642877249411,"firstId":279,"lastId":279,"count":1},{"symbol":"TRXBUSD","priceChange":"0.03232000","priceChangePercent":"32.000","weightedAvgPrice":"0.11076213","prevClosePrice":"0.10100000","lastPrice":"0.13332000","lastQty":"1523.50000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.13332000","askQty":"88476.50000000","openPrice":"0.10100000","highPrice":"0.13332000","lowPrice":"0.10100000","volume":"16818.90000000","quoteVolume":"1862.89722000","openTime":1643122833061,"closeTime":1643209233061,"firstId":1249,"lastId":1294,"count":46},{"symbol":"XRPBUSD","priceChange":"-0.01810000","priceChangePercent":"-2.854","weightedAvgPrice":"0.61992932","prevClosePrice":"0.63450000","lastPrice":"0.61610000","lastQty":"1000.50000000","bidPrice":"0.61610000","bidQty":"379.20000000","askPrice":"0.61760000","askQty":"1123.30000000","openPrice":"0.63420000","highPrice":"0.63420000","lowPrice":"0.61020000","volume":"108098.80000000","quoteVolume":"67013.61575000","openTime":1643275083974,"closeTime":1643361483974,"firstId":8697,"lastId":8878,"count":182},{"symbol":"BNBUSDT","priceChange":"15.70000000","priceChangePercent":"4.263","weightedAvgPrice":"378.25471882","prevClosePrice":"368.30000000","lastPrice":"384.00000000","lastQty":"11.24000000","bidPrice":"384.00000000","bidQty":"1.07000000","askPrice":"384.10000000","askQty":"6.70000000","openPrice":"368.30000000","highPrice":"1850.00000000","lowPrice":"74.20000000","volume":"71349.31000000","quoteVolume":"26988213.19210000","openTime":1643281621223,"closeTime":1643368021223,"firstId":343601,"lastId":355850,"count":12250},{"symbol":"BTCUSDT","priceChange":"108.79000000","priceChangePercent":"0.299","weightedAvgPrice":"36644.68429030","prevClosePrice":"36409.39000000","lastPrice":"36518.19000000","lastQty":"0.06572100","bidPrice":"36522.25000000","bidQty":"0.02846000","askPrice":"36524.95000000","askQty":"0.06160200","openPrice":"36409.40000000","highPrice":"37489.80000000","lowPrice":"35533.92000000","volume":"3395.86321500","quoteVolume":"124440335.40672936","openTime":1643281621290,"closeTime":1643368021290,"firstId":2418840,"lastId":2506928,"count":88089},{"symbol":"ETHUSDT","priceChange":"-662.84000000","priceChangePercent":"-30.661","weightedAvgPrice":"1820.66870669","prevClosePrice":"2161.82000000","lastPrice":"1498.98000000","lastQty":"0.06000000","bidPrice":"1476.50000000","bidQty":"0.54404000","askPrice":"1521.46000000","askQty":"2.55087000","openPrice":"2161.82000000","highPrice":"2161.82000000","lowPrice":"1241.43000000","volume":"120.85860000","quoteVolume":"220043.47095490","openTime":1643281618572,"closeTime":1643368018572,"firstId":53006,"lastId":53645,"count":640},{"symbol":"LTCUSDT","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"438.17565832","prevClosePrice":"461.06000000","lastPrice":"461.06000000","lastQty":"2.48345000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"461.06000000","askQty":"101.80756000","openPrice":"461.06000000","highPrice":"461.06000000","lowPrice":"350.00000000","volume":"10.28616000","quoteVolume":"4507.14492960","openTime":1643265940862,"closeTime":1643352340862,"firstId":2312,"lastId":2331,"count":20},{"symbol":"TRXUSDT","priceChange":"0.00266000","priceChangePercent":"4.890","weightedAvgPrice":"0.06827562","prevClosePrice":"0.05440000","lastPrice":"0.05706000","lastQty":"1752.50000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.05706000","askQty":"356.50000000","openPrice":"0.05440000","highPrice":"0.10000000","lowPrice":"0.05440000","volume":"42086.70000000","quoteVolume":"2873.49573600","openTime":1643260927793,"closeTime":1643347327793,"firstId":2646,"lastId":2709,"count":64},{"symbol":"XRPUSDT","priceChange":"7.13270000","priceChangePercent":"1.858","weightedAvgPrice":"386.25031010","prevClosePrice":"391.04500000","lastPrice":"391.04500000","lastQty":"162.80000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"391.04500000","askQty":"49663.30000000","openPrice":"383.91230000","highPrice":"391.04500000","lowPrice":"300.00000000","volume":"184.10000000","quoteVolume":"71108.68209000","openTime":1643258286905,"closeTime":1643344686905,"firstId":9343,"lastId":9361,"count":19},{"symbol":"BNBBTC","priceChange":"0.00016900","priceChangePercent":"1.660","weightedAvgPrice":"0.01019432","prevClosePrice":"0.01300000","lastPrice":"0.01035000","lastQty":"0.95000000","bidPrice":"0.01149200","bidQty":"0.20000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.01018100","highPrice":"0.01039000","lowPrice":"0.01018100","volume":"13.03000000","quoteVolume":"0.13283204","openTime":1643117676485,"closeTime":1643204076485,"firstId":316,"lastId":324,"count":9},{"symbol":"ETHBTC","priceChange":"-0.00374300","priceChangePercent":"-5.464","weightedAvgPrice":"0.06492456","prevClosePrice":"0.08000000","lastPrice":"0.06475700","lastQty":"64.01412000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.07780000","askQty":"70.92430000","openPrice":"0.06850000","highPrice":"0.06850000","lowPrice":"0.06475700","volume":"67.01412000","quoteVolume":"4.35086236","openTime":1643276240832,"closeTime":1643362640832,"firstId":3103,"lastId":3104,"count":2},{"symbol":"LTCBTC","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00000000","prevClosePrice":"0.00319700","lastPrice":"0.00000000","lastQty":"0.00000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.00000000","highPrice":"0.00000000","lowPrice":"0.00000000","volume":"0.00000000","quoteVolume":"0.00000000","openTime":1642974551206,"closeTime":1643060951206,"firstId":-1,"lastId":-1,"count":0},{"symbol":"TRXBTC","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00000222","prevClosePrice":"0.00000165","lastPrice":"0.00000222","lastQty":"6060.00000000","bidPrice":"0.00000168","bidQty":"59.60000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.00000222","highPrice":"0.00000222","lowPrice":"0.00000222","volume":"6060.00000000","quoteVolume":"0.01345320","openTime":1643121796546,"closeTime":1643208196546,"firstId":5,"lastId":5,"count":1},{"symbol":"XRPBTC","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00001650","prevClosePrice":"0.00001650","lastPrice":"0.00001650","lastQty":"11.00000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00001650","askQty":"12489.00000000","openPrice":"0.00001650","highPrice":"0.00001650","lowPrice":"0.00001650","volume":"11.00000000","quoteVolume":"0.00018150","openTime":1643194419610,"closeTime":1643280819610,"firstId":1536,"lastId":1536,"count":1},{"symbol":"LTCBNB","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00000000","prevClosePrice":"0.17450000","lastPrice":"0.00000000","lastQty":"0.00000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.00000000","highPrice":"0.00000000","lowPrice":"0.00000000","volume":"0.00000000","quoteVolume":"0.00000000","openTime":1642847149592,"closeTime":1642933549592,"firstId":-1,"lastId":-1,"count":0},{"symbol":"TRXBNB","priceChange":"0.00000030","priceChangePercent":"0.200","weightedAvgPrice":"0.00014987","prevClosePrice":"0.00000000","lastPrice":"0.00015000","lastQty":"1000.00000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.00014970","highPrice":"0.00015010","lowPrice":"0.00014970","volume":"4000.00000000","quoteVolume":"0.59950000","openTime":1641243788364,"closeTime":1641330188364,"firstId":0,"lastId":3,"count":4},{"symbol":"XRPBNB","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00162700","prevClosePrice":"0.00162700","lastPrice":"0.00162700","lastQty":"90000.00000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.00162700","highPrice":"0.00162700","lowPrice":"0.00162700","volume":"90000.00000000","quoteVolume":"146.43000000","openTime":1642126497120,"closeTime":1642212897120,"firstId":8,"lastId":906,"count":899}]

SORRY about the giant objects, but just wanted to use the real data I am using. The main point is that the first body is a singular objects, and the second is an array of objects.

Thanks

@jared.gibb Would you be able to shed some light on how to return arrays of objects? I’m struggling with this on a variety of API calls similar to this above comment.

Did you see the very first video in this thread? :crazy_face:

Where do you get lost? Wanna share a code example?

Hi @jared.gibb , yes the first video was extremely helpful and I’, successfully returning objects from my plugin calls. My issue is when I have an array of objects rather than a singular object to return.

My action code is the following:

function(properties, context) {
  
    var burl = ''
    , query = ''
    , method = 'GET'
    , testa = '';
    
 
    const ts = Date.now();

var crypto = require('crypto-js')
    

                  , text = 'timestamp=' + Date.now()
                  , skey = properties.secret_key
                  , hash
					, symbolinput = properties.symbol.trim()
					, symbola = ''					
					, symbol = '';
    
    if (properties.testnet.toString() == "false")
    	burl = 'https://api.binance.com/api/v3/';
    else
        burl = 'https://testnet.binance.vision/api/v3/';
   

if (symbolinput.length > 0){
		symbola = symbolinput.toUpperCase();
    	symbol = "?symbol=" + symbola.replace(/\s+/g, ' ').trim()
}
    
if (properties.endpoint.trim() == "Current Average Price"){
    var query = 'avgPrice' + symbol;
}

if (properties.endpoint.trim() == "24hr Ticker Price Change Statistics"){
    var query = 'ticker/24hr' + symbol;
}
    				
var hash = crypto.HmacSHA256(text, skey).toString()
	, url = burl + query

const options = {
    url: url
    ,method: method
    ,headers: {
        "Content-Type": "application/json"
    }
}


const response = context.request(options);
	console.log(response);
    

var body = JSON.parse(response.body);

const {convert} = require('json-to-bubble-object');
        
let returnlist = []
returnlist.push(convert(body))
                
    return {
        "result": returnlist,
        "api_result": JSON.stringify(body)
    
    }
}

When I specify a Symbol, the result is returned as the following


Demo Login
{"symbol":"BTCUSDT","priceChange":"3682.66000000","priceChangePercent":"9.959","weightedAvgPrice":"38562.22336739","prevClosePrice":"36978.77000000","lastPrice":"40661.51000000","lastQty":"0.00491600","bidPrice":"40661.53000000","bidQty":"0.05017100","askPrice":"40661.54000000","askQty":"0.05951600","openPrice":"36978.85000000","highPrice":"60000.00000000","lowPrice":"7500.00000000","volume":"3571.14095500","quoteVolume":"137711135.18314058","openTime":1643929763213,"closeTime":1644016163213,"firstId":332519,"lastId":475709,"count":143191}

and the object is returned and displayed in my RG

But when I don’t specify a Symbol (which returns all symbols data), the response is an ARRAY of objects like as follows, and all the fields are displayed as null.


Demo Login
[{"symbol":"BNBBUSD","priceChange":"-260.30000000","priceChangePercent":"-72.245","weightedAvgPrice":"261.29676153","prevClosePrice":"380.00000000","lastPrice":"100.00000000","lastQty":"0.10000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"400.00000000","askQty":"16.61000000","openPrice":"360.30000000","highPrice":"400.00000000","lowPrice":"100.00000000","volume":"101.90000000","quoteVolume":"26626.14000000","openTime":1643928538140,"closeTime":1644014938140,"firstId":167,"lastId":229,"count":63},{"symbol":"BTCBUSD","priceChange":"-397015.20000000","priceChangePercent":"-96.928","weightedAvgPrice":"199767.05017855","prevClosePrice":"15731.00000000","lastPrice":"12584.80000000","lastQty":"0.01770000","bidPrice":"12584.80000000","bidQty":"0.00794600","askPrice":"800000.00000000","askQty":"0.00312900","openPrice":"409600.00000000","highPrice":"1000000.00000000","lowPrice":"12584.80000000","volume":"0.10249400","quoteVolume":"20474.92404100","openTime":1643929869031,"closeTime":1644016269031,"firstId":984,"lastId":1112,"count":129},{"symbol":"ETHBUSD","priceChange":"317.96000000","priceChangePercent":"12.166","weightedAvgPrice":"2682.22056263","prevClosePrice":"2715.36000000","lastPrice":"2931.38000000","lastQty":"0.03411000","bidPrice":"2612.40000000","bidQty":"0.23518000","askPrice":"2931.38000000","askQty":"0.03483000","openPrice":"2613.42000000","highPrice":"2931.38000000","lowPrice":"2612.40000000","volume":"11.89729000","quoteVolume":"31911.15587760","openTime":1643929208027,"closeTime":1644015608027,"firstId":1201,"lastId":1271,"count":71},{"symbol":"LTCBUSD","priceChange":"-10.40000000","priceChangePercent":"-9.420","weightedAvgPrice":"109.56956955","prevClosePrice":"110.00000000","lastPrice":"100.00000000","lastQty":"0.18116000","bidPrice":"100.00000000","bidQty":"4.81884000","askPrice":"110.40000000","askQty":"7.91238000","openPrice":"110.40000000","highPrice":"110.40000000","lowPrice":"100.00000000","volume":"2.26878000","quoteVolume":"248.58924800","openTime":1643927358794,"closeTime":1644013758794,"firstId":6,"lastId":13,"count":8},{"symbol":"TRXBUSD","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00000000","prevClosePrice":"0.06018000","lastPrice":"0.00000000","lastQty":"0.00000000","bidPrice":"0.05955000","bidQty":"1000.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.00000000","highPrice":"0.00000000","lowPrice":"0.00000000","volume":"0.00000000","quoteVolume":"0.00000000","openTime":1643846868283,"closeTime":1643933268283,"firstId":-1,"lastId":-1,"count":0},{"symbol":"XRPBUSD","priceChange":"-0.01760000","priceChangePercent":"-2.940","weightedAvgPrice":"0.60186777","prevClosePrice":"0.59880000","lastPrice":"0.58100000","lastQty":"172.10000000","bidPrice":"0.57500000","bidQty":"1652.20000000","askPrice":"0.59310000","askQty":"172.10000000","openPrice":"0.59860000","highPrice":"0.61060000","lowPrice":"0.56100000","volume":"108426.80000000","quoteVolume":"65258.59666000","openTime":1643928550344,"closeTime":1644014950344,"firstId":605,"lastId":782,"count":178},{"symbol":"BNBUSDT","priceChange":"26.80000000","priceChangePercent":"7.251","weightedAvgPrice":"380.08239973","prevClosePrice":"369.50000000","lastPrice":"396.40000000","lastQty":"6.35000000","bidPrice":"396.40000000","bidQty":"2.28000000","askPrice":"396.50000000","askQty":"6.92000000","openPrice":"369.60000000","highPrice":"398.20000000","lowPrice":"80.00000000","volume":"41526.98000000","quoteVolume":"15783674.21180000","openTime":1643929863662,"closeTime":1644016263662,"firstId":70606,"lastId":78117,"count":7512},{"symbol":"BTCUSDT","priceChange":"3647.90000000","priceChangePercent":"9.859","weightedAvgPrice":"38564.23034247","prevClosePrice":"37000.16000000","lastPrice":"40647.14000000","lastQty":"0.00250000","bidPrice":"40647.13000000","bidQty":"0.07019500","askPrice":"40647.14000000","askQty":"0.06589400","openPrice":"36999.24000000","highPrice":"60000.00000000","lowPrice":"7500.00000000","volume":"3568.59494800","quoteVolume":"137620117.57363274","openTime":1643929870517,"closeTime":1644016270517,"firstId":332606,"lastId":475743,"count":143138},{"symbol":"ETHUSDT","priceChange":"-79.19000000","priceChangePercent":"-7.999","weightedAvgPrice":"946.20699162","prevClosePrice":"992.02000000","lastPrice":"910.85000000","lastQty":"0.01207000","bidPrice":"909.03000000","bidQty":"0.13365000","askPrice":"912.67000000","askQty":"18.62675000","openPrice":"990.04000000","highPrice":"2373.20000000","lowPrice":"463.14000000","volume":"581.75887000","quoteVolume":"550464.31023250","openTime":1643929804202,"closeTime":1644016204202,"firstId":1614,"lastId":2846,"count":1233},{"symbol":"LTCUSDT","priceChange":"-10.50000000","priceChangePercent":"-9.013","weightedAvgPrice":"110.36943858","prevClosePrice":"116.50000000","lastPrice":"106.00000000","lastQty":"281.14085000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"106.00000000","askQty":"218.85915000","openPrice":"116.50000000","highPrice":"116.50000000","lowPrice":"106.00000000","volume":"481.51853000","quoteVolume":"53144.92982000","openTime":1643929803923,"closeTime":1644016203923,"firstId":170,"lastId":273,"count":104},{"symbol":"TRXUSDT","priceChange":"-0.03676000","priceChangePercent":"-36.760","weightedAvgPrice":"0.07982987","prevClosePrice":"0.10000000","lastPrice":"0.06324000","lastQty":"1903.00000000","bidPrice":"0.06355000","bidQty":"1888.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.10000000","highPrice":"1.49575000","lowPrice":"0.05800000","volume":"44517.00000000","quoteVolume":"3553.78628000","openTime":1643884562781,"closeTime":1643970962781,"firstId":144,"lastId":210,"count":67},{"symbol":"XRPUSDT","priceChange":"-0.10000000","priceChangePercent":"-16.667","weightedAvgPrice":"0.61590748","prevClosePrice":"0.60000000","lastPrice":"0.50000000","lastQty":"300.00000000","bidPrice":"0.50000000","bidQty":"183.20000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.60000000","highPrice":"3.08800000","lowPrice":"0.50000000","volume":"13689.80000000","quoteVolume":"8431.65024000","openTime":1643926264152,"closeTime":1644012664152,"firstId":332,"lastId":476,"count":145},{"symbol":"BNBBTC","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00991409","prevClosePrice":"0.00993100","lastPrice":"0.00993100","lastQty":"0.31000000","bidPrice":"0.00893100","bidQty":"0.10000000","askPrice":"0.00993100","askQty":"672.80000000","openPrice":"0.00993100","highPrice":"0.00993100","lowPrice":"0.00731000","volume":"103.63000000","quoteVolume":"1.02739693","openTime":1643927113274,"closeTime":1644013513274,"firstId":206,"lastId":231,"count":26},{"symbol":"ETHBTC","priceChange":"0.22787000","priceChangePercent":"315.916","weightedAvgPrice":"0.24303250","prevClosePrice":"0.07214500","lastPrice":"0.30000000","lastQty":"3.00000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.30000000","askQty":"9.00000000","openPrice":"0.07213000","highPrice":"0.30000000","lowPrice":"0.07213000","volume":"4.00000000","quoteVolume":"0.97213000","openTime":1643884608187,"closeTime":1643971008187,"firstId":8,"lastId":9,"count":2},{"symbol":"LTCBTC","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00000000","prevClosePrice":"0.00287400","lastPrice":"0.00000000","lastQty":"0.00000000","bidPrice":"0.00297700","bidQty":"1.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.00000000","highPrice":"0.00000000","lowPrice":"0.00000000","volume":"0.00000000","quoteVolume":"0.00000000","openTime":1643883202421,"closeTime":1643969602421,"firstId":-1,"lastId":-1,"count":0},{"symbol":"TRXBTC","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00000156","prevClosePrice":"0.00000156","lastPrice":"0.00000156","lastQty":"512.80000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000156","askQty":"344.70000000","openPrice":"0.00000156","highPrice":"0.00000156","lowPrice":"0.00000156","volume":"512.80000000","quoteVolume":"0.00079996","openTime":1643873130126,"closeTime":1643959530126,"firstId":6,"lastId":9,"count":4},{"symbol":"XRPBTC","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00001627","prevClosePrice":"0.00001627","lastPrice":"0.00001627","lastQty":"158.60000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00001627","askQty":"65.60000000","openPrice":"0.00001627","highPrice":"0.00001627","lowPrice":"0.00001627","volume":"158.60000000","quoteVolume":"0.00258040","openTime":1643873454115,"closeTime":1643959854115,"firstId":10,"lastId":15,"count":6},{"symbol":"LTCBNB","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.30569997","prevClosePrice":"0.29970000","lastPrice":"0.30570000","lastQty":"0.25967000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.30570000","highPrice":"0.30570000","lowPrice":"0.30570000","volume":"0.25967000","quoteVolume":"0.07938111","openTime":1643865673352,"closeTime":1643952073352,"firstId":6,"lastId":6,"count":1},{"symbol":"TRXBNB","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00000000","prevClosePrice":"0.00015750","lastPrice":"0.00000000","lastQty":"0.00000000","bidPrice":"0.00016130","bidQty":"98574.20000000","askPrice":"0.00016150","askQty":"94117.70000000","openPrice":"0.00000000","highPrice":"0.00000000","lowPrice":"0.00000000","volume":"0.00000000","quoteVolume":"0.00000000","openTime":1643924658455,"closeTime":1644011058455,"firstId":-1,"lastId":-1,"count":0},{"symbol":"XRPBNB","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"0.00163800","prevClosePrice":"0.00162800","lastPrice":"0.00163800","lastQty":"1000.00000000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"0.00163800","highPrice":"0.00163800","lowPrice":"0.00163800","volume":"1000.00000000","quoteVolume":"1.63800000","openTime":1643691995629,"closeTime":1643778395629,"firstId":3,"lastId":3,"count":1}]

The key thing to note is the difference, which I think is causing my problems. I am receiving the api result, but for some reason the returnlist function is not returning the result. I feel I am doing something obviously wrong but I’m having trouble figuring it out. I think It may be because bubble thinks I’m returning an array rather than an object

How did you define your return value?

How did you define your custom data type I. The api connector?

Idk how that library works to bubblize JSON bodies. I’d recommend doing this step yourself.

What does the response from the api look like when you request 1 vs all tokens?

@jared.gibb Thanks for your help. I have solved the problem. For anyone else with issues of returning Arrays of objects, my solution is the following code"


const response = context.request(options);
	console.log(response);
    

var body = JSON.parse(response.body);

const {convert} = require('json-to-bubble-object');
        
let returnlist = []

if (Array.isArray(body) == false){
returnlist.push(convert(body))
}
    else {
        for (let i = 0; i < body.length; i++) {
  returnlist[i] = convert(body[i]);
}
    }
        
                
    return {
        "result": returnlist,    
    }
}

Essentially, if the returned API data is just one single object, without [], we can pass that through as per the usual. If not, Iterate through each object in the array and use the convert function to include the p prefix to each object. This then allows it to be passed back through the API as a list.

Would love some help returning a value client side from an action - so far this seems impossible!

Did you see the video above? Which part didn’t work for you?

Hi @jared.gibb ,

Mostly the part where there was no video :wink:

Although on further reading, I don’t believe it’s possible with Client Side actions

Cheers
Simon

@jared.gibb Hey Jared, First, thank you for taking the time to thoroughly outline and explain these steps! This is enormously helpful. I have a followup question for you or anybody that can answer. Perhaps you will cover this in video 2, but I’m not sure, so I’ll go head and ask here.

How do you pass dynamic url parameters from the API call tab to the elements tab for use in the code on the elements and/or actions tab?

Essentially, I want to use/transform a dynamic variable(s) provided from the “get data from API” feature, before returning the response as JSON.

Adding the parameter is easy, I’m just perplexed about how to call it and assign it as a variable in the actual code. Maybe it’s obvious, but I haven’t seen any documentation on how to explicitly do this.

awesome, thanks!

Hello Everybody,

First of all, thank you very much @jared.gibb for this full tutorial, it’s help me a lot, and I think I (finally) understand some basics. It’s real game changer for bubble building.

Second, English is not my native language, so I’m sorry if some things are not clear. Plus i’m not a “coder” and I have just very few knowledges about JS et nodejs.

Third, PLEEEEAAASE I need your help. I’m struggle with this for weeks, so there it is :

I’m trying to create a plugin for calculate Levenshtein Distance.
If you don’t know what it is, it’s the difference between to strings (e.g : love/love = 0 because it’s the same word, love/hate = 3 because 3 letters has been changed… )

for that I use the nodejs package levenshtein.

I need to catch the result (levenshtein.distance) and change a cell’s data of my bubble DB.
I use server side action, because I need to loop the worklow.

Here is how I process :

1 - The user click on the button, the first action launch the API Workflow.

2 - Here is the API Worklow launched. First step, is ok then, I launch my plugin SCORE

3 - I want to keep the result on the database in a user field in the next step

That where it’s not working.

So plugin side :

1 - Plugin API Calls

2 - API Response


3 - Values

4 - Code

5 - SSA Console Output

If I change the console.log(score) to return {“score_titre” : score}, nothing happend… I don’t get it.
I don’t know what I missing or if use it the wrong way ?

Thank you very much for reading me and your help!!

Tewfiq

You never return {“some”:”value”}

You probably want to

return {
“_p_score_titre”: levscore.distance
}

But you probably have an async action happening there and you’ll need more code than that if true

Thank for your answer.
Actually, I try both way and the both return nothing.

But… just with this

function(properties, context) {
		var levenshtein = require("levenshtein")
		var srt1 = properties.reponsetitre
		var srt2 = properties.sessiontitre
		var levscore = new levenshtein(srt1,srt2)
    
		var score = levscore.distance
        
return {"score_titre": score};
    
}

I have the response.
I don’t understand why, but it’s working

The reason it works is because score_titre is the name of the return field that you defined in your returned values above. It appears that levscore.distance is simply a number. You don’t need to define the API type to return a simple type like a number.

Maybe your end goal/hope is to return more than just the distance value. But as your code is currently I think you have slightly overcomplicated the concept.

do a search for a plugin called “Return a bubble thing”

see it in action here

its a demo i made. be sure to check out the code. this is what you are shooting for.

Thank you, it’s more clear now!

And yes, I have overcomplicated the concept!! But, reassure me, it’s newbies mistakes no ??

Thank you so much for your work !!

Excellent tutorials, @jared.gibb . I love the name of the test app poop123. I’m here for that.

Thanks for sharing this tutorial !!
I’m struggling to make it work I get an error when parsing the response.

Can anyone help me here? I must be missing something but I cannot find it

This is my setup: