I am using the bubble.io plugin builder. To return a response under bubble.io's api connector, all parameters returned must have the prefix "p". In the following case, this returns the correct results for an api call.
const options = {
url: url
,method: method
,headers: {
"Content-Type": "application/json"
}
}
const response = context.request(options);
console.log(response);
/*
The model we will use
{
"mins": 5,
"price": "34823.91104827"
}
*/
var body = JSON.parse(response.body);
const {convert} = require('json-to-bubble-object');
let returnlist = []
returnlist.push( {
"_p_mins": body.mins.toString(),
"_p_price": body.price,
"_p_api_response": JSON.stringify(convert(body))
})
return {
"result": returnlist
}
This call generates the following response:
_p_api_response: "{"_p_mins":5,"_p_price":"36703.73207769"}"
_p_mins: "5"
_p_price: "36703.73207769"
What I am trying to do is use the module 'json-to-bubble-object' as returned in the _p_api_response parameter (which is a test parameter and is not actually needed) to return the data. This makes my call dynamic so I don't have to manually specify the parameters for each different api call.
Hence, I am trying to make the API call look something like this:
var body = JSON.parse(response.body);
const {convert} = require('json-to-bubble-object');
let returnlist = []
returnlist.push( JSON.stringify(convert(body))
)
return {
"result": returnlist
}
but this returns null results
_p_api_response: null
_p_mins: null
_p_price: null
can someone let me know how I can return the data generated from the convert function as a list as done in the first request? Thanks
EDIT: For clarification, the p prefix allows the response headers to be viewed in the bubble.io builder, as seen in the below image.
I dont have enough reputation to comment but
I am unable to repro your problem. You can view my repro here:
https://runkit.com/runkitname/so-a-nodejs
const {convert} = require('json-to-bubble-object');
var body = {
"mins": 5,
"price": "34823.91104827"
}
body.api_response = JSON.stringify(convert(body))
let returnlist = []
returnlist.push(convert(body))
console.log({"result": returnlist})
console
{
result: [
{
_p_mins: 5,
_p_price: '34823.91104827',
_p_api_response: '{"_p_mins":5,"_p_price":"34823.91104827"}'
}
]
}