Using API Calls within Tag

Hello,
we have an AzureFunction to check an ID in the URL-Parameters to prevent duplication. Therefore, I need to call the server-url within a Tag or Variable and get the response status (200 or 409).
But calling it with javascript fetch(url) doesn’t work for me, neither does the old XHR-Request.

I tried something like this for testing:
fetch(apiUrl)
.then(response => {
if (response.status === 200) {
console.log(‘ok’);
} else if (response.status === 409) {
console.log(‘not ok’);
} else {
console.log(Unexpected status: ${response.status});
}
})
.catch(error => {
console.error(‘Error making API call:’, error);
});

I get the following error:
“Fetch error: TypeError: Failed to fetch”

To me it looks like the sandboxed Matomo Javascript doesn’t allow this.
Does anyone have experience with this and can help me?

maybe a CORS problem? Check browser console logs for specific CORS-related errors.

The issue might be related to CORS restrictions or Matomo’s sandbox preventing external requests. It would be worth checking the browser console for more details and testing the API endpoint outside Tag Manager first. That should help narrow down where the request is failing.