Send an array as Parameter REST API, is it possible with Appgyver?

Hi! I’m new here and I’m trying to GET my data from bubble’s backend, but in their documentation they explicitly say that the constraint (of search) have to be pass as an array “This parameter should be an array of constraints” and it should look like this:

constraints = [
{
“key”: “name”,
“constraint_type”: “text contains”,
“value”: “cafe”
}
,
{
“key”: “address”,
“constraint_type”: “geographic_search”,
“value”: {
“range”:10,
“origin_address”:“New York”
}
}
]

Is it possible from Appgyver to do that? I couldn’t find a way :frowning:

Query parameters are by their nature text strings, so if you have e.g. an app variable constraints that has your array/list in the right format, you can pass it as ENCODE_JSON(appVars.constraints) (or just write the JSON inline in the formula editor, then wrap it with ENCODE_JSON).

1 Like

Thank you! It worked :smiley:

Hi Harri, Could you please elaborate in more details how does it looks like exactly?

In my case I have the request JSON, before getting stringified (whatever it means):
let request_data = {
‘facets’: {
‘make’: [‘audi’],
‘vehicle_type’: []
},
‘query_args’: {
‘post_type’: ‘cars’,
‘posts_per_page’: 4,
‘paged’: 1
}
}

Then using the example comes a javascript request:
const response = fetch(‘https://yoursite.com/wp-json/facetwp/v1/fetch’, {
‘method’: ‘POST’,
‘headers’: {
‘Authorization’: 'Basic ’ + btoa(‘username:password’) // base64-encoded
},
‘body’: {
‘data’: JSON.stringify(request_data) // stringified!
}
})
.then(function(response) {
console.log(response);
});

The authorization and other stuffs are ok, but would be nice to understand your suggestion in details.

I beleive I need to set up app variable as request_data - It should be a list type variable. Now I lost it here. So move on to the inline JSON format. Should it look like this?:
'facets': { 'make': ['audi'], 'vehicle_type': [] }, 'query_args': { 'post_type': 'cars', 'posts_per_page': 4, 'paged': 1 } }

where the appVar.request_data variable keeps it as initial value?

The Create record flow function stringifies the body automatically, so you can just pass the whole request_data object to the flow function without having to run it through a formula.

The question above was how to include list/object data in GET request query parameters, which requires the ENCODE_JSON to turn it into a text string.