When I run this JS query, the logging shows that the “distinction_healthchecks” queries being executed are hitting the URL https://my-health-check-domain.com/_health-undefined despite the additional containing a valid string value.
I'd need to see your distinction_healthchecks function setup to know for sure what might be causing your issues, but assuming it is indeed configured properly and returns data as expected, try the following simplified code to see if it helps with debugging.
const codenames = health_checks.value
if (codenames.length === 0) return []
const promises = []
for(const codename of codenames) {
const params = {client_healthcheck_name: codename}
promises.push(distinction_healthcheck.trigger( { additionalScope: params } ))
}
const rawData = await Promise.all(promises)
const mergedData = rawData.map(d => d.data) // Because they all come out on the data property of the resolved data, this just cleans it up
return mergedData
You can log out the rawData to help with debugging and see if you can narrow down if something is going wrong.
The query is a simple GET request to a URL with the structure https://my-health-check-domain.com/_health-{{client_healthcheck_name}}
The issue seems to be that when called from a JS Query using additionalScope to pass the parameter, the parameter never actually gets passed so the query sends the GET request to https://my-health-check-domain.com/_health-**undefined** which, of course, returns a 404.
For anyone else that finds this, the answer is to add your parameters as variables in the query pane.
In my case this meant I needed to enter {{client_healthcheck_name}} into the client_healthcheck_name parameter field on the distinction_healthchecks REST query.
This will show red as an unknown variable but will work when called from the JS query.
This is super counter-intuitive and not covered in the official documentation.