Thanks @JohnGill and @Bart
I’m using globals keywords with the method described here: Problems with keyword replacement values as modifiers
I have a REST Resource asset (#12345) setup as follows:
URL: https://%globals_get_parameters%/v2/posts.json
<script>
var response = JSON.parse(_REST.response.body),
limit = %globals_get_numberToReturn%;
var newArray = [];
for (i = 0; i < limit; i++) {
var newStructure = {
"local_asset": false,
"platform": "Blogs",
"use_target_blank": true,
"type": "news",
"id": response[i].id
};
newArray.push(newStructure);
}
print(newArray);
</script>
It returns:
[
{
"local_asset": false,
"platform": "Blogs",
"use_target_blank": true,
"type": "news",
"id": 623
},
{
"local_asset": false,
"platform": "Blogs",
"use_target_blank": true,
"type": "news",
"id": 599
},
{
"local_asset": false,
"platform": "Blogs",
"use_target_blank": true,
"type": "news",
"id": 588
}
]
In the paint layout, I declare some variables that are passed to the REST Resource asset and then attempt to assign the output to a variable.
<script>
var parameters = '%asset_metadata_test%',
numberToReturn = 3;
// This is the REST Resource asset that calls an API endpoint based on the parameters passed to it with the GET variable and returns a JSON array of objects (as above). Works fine printing to the frontend.
print('%' + 'globals_asset_contents:12345^with_get:params=' + parameters + '^with_get:numberToReturn=' + numberToReturn + '%');
// I want to assign the output from the above print statement to a variable
// EXAMPLE 1 - try to assign to the variable using the print statement
// example1 just prints the objects directly to the frontend: '[object Object],[object Object]' etc.
var example1 = print('%' + 'globals_asset_contents:12345^with_get:params=' + parameters + '^with_get:numberToReturn=' + numberToReturn + '%');
// example1 is a 'number'
print(typeof example1);
// EXAMPLE 2 - try to assign to the variable without the print statement
var example2 = '%' + 'globals_asset_contents:12345^with_get:params=' + parameters + '^with_get:numberToReturn=' + numberToReturn + '%';
// is a 'string'
print(typeof example2);
print(example2[0]); // returns '%'
</script>
I had a quick look at the method suggested by @JohnGill but I suspect that doesn’t allow me to pass the additional GET parameters through that I need.