Question:
Hello, I’m working on fetching an API call, all is working properly in my preview but if I publish the site, I got the following error:
createConsoleProxy.ts:47 Error: Unable to handle the request. Contact the site administrator or view site monitoring logs for more information.
Product:
Editor X
What are you trying to achieve:
API Call to get information from 3rd party site.
What have you already tried:
Check permissions, read similar forum information, google it. Nothing worked.
Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]
Hi Pratham, thanks for your response. It is a POST call to an HTTPS end point, then I manage the response. All is working properly in the preview version but if I publish the site, I get the error described above.
Please find below my code:
import { getAuthCode, getRegions } from 'backend/newDataFetcher';
// See the dataFetcher.jsw web module in the backend for the fetch calls //
$w.onReady(function () {
// setupInitialUI();
$w('#button2').onClick(onButton2Click);
});
async function onButton2Click() {
$w('#button2').disable();
await getDrowpdownFilled();
$w('#button2').enable();
}
//Get dropdownfilled
async function getDrowpdownFilled() {
const regions = await getRegions();
// Extracting 'descr' fields
const descrFields = regions.data.map(item => {
return {
label: item.descr,
value: item.id // You can use a different field as the value if needed
};
});
$w('#dropdown1').options = descrFields;
}
//Get authcode
async function getAuthCodeFront() {
//console.log("before putResponse");
const putResponse = await getAuthCode();
}
// Sample backend code in a multiplication.jsw file:
import { fetch, getJSON } from 'wix-fetch';
// CONST
const urlRegion = "https://www.irc-com.it/irccombo/anagrafica/tabelle/ListTabella";
// Var
let authToken = "non-auth-code-yet";
const bodyAuth = {
request: 'login',
lang: 'it',
username: ‘XXXXXXXXXXXXXX’,
password: ‘XXXXXXXXXXXXXXx’
};
const fetchOptionsAuth = {
method: 'post',
headers: 'application/json',
body: JSON.stringify(bodyAuth)
};
// POST call to get authentication token.
export async function getAuthCode() {
console.log("Generating Auth Code");
const response = await fetch(urlAuth, fetchOptionsAuth);
if (response.ok) {
const data = await response.json(); // Parse the JSON response
authToken = data.token; // Replace 'node' with the key of the specific node you want
// Use the specificNode data
console.log('Auth Code Generated');
} else {
console.error('Failed to fetch data');
}
return authToken;
}
// POST call to get regions
export async function getRegions() {
console.log("Getting regions");
//console.log("Generating Auth Code");
authToken = await getAuthCode();
// Region consult body
let bodyRegion = {
"model_name": "regioni",
"page": 1,
"limit": 10000,
"order": "asc",
"token": authToken
};
// Region fetch options
const fetchOptionsRegion = {
method: 'post',
headers: 'application/json',
body: JSON.stringify(bodyRegion)
};
const response = await fetch(urlRegion, fetchOptionsRegion);
return response.json();
}
Did you check the console.logs on the preview and the live site simultaneously? Since you’ve added them throughout the code, checking the console may help you find exactly where the error is occurring.
I have more information, the API is using cloudflare and for some reason in the live site I getting a “wait a second” html display and not the direct response from the API.
Does anyone knows why this behavior is not the same for the preview site? is there a way to configure the live site to behave as the preview site for the API fetch?
But in your code, you’ve used await so that should’ve taken care of the issue…
Which is why I’ve tagged the devs from the Wix team to shed some light on this, since they can access your site directly.
Or you can try reaching out to the Velo support team here.
I’m not sure why. Just a guess would be that the preview and live backend functions are being executed from different buckets with different IPs and this might feed into why cloudflare is choosing to captcha one and not the other.
Ultimately though the endpoint you’re querying is running on cloudflare so there’s not much we can help debug here since cloudflare would be making the decision on whether to serve the response or a captcha. The captcha issue would need to be solved on cloudflare’s end.