What is the name of the domain?
ozicybernomad dot com
What is the error number?
It just doesn’t work
What is the issue you’re encountering
I have a new AI server I am trying to interact with protected behind a Cloudflare tunnel. I need to drive it with information from Google sheets (through google apps script). I am having trouble understanding how I need to structure the script so that it passes the appropriate token to Cloudflare and then passes the appropriate token to the AI server once it is redirected. To be honest I am not sure how to configure CF to allow me to do that and I cannot find any advice.
What steps have you taken to resolve the issue?
Here’s my latest attempt:
function queryAi(client, message) {
// Replace with your actual tokens and URLs
var apiToken = ‘ABCDE-FGHIJ-KLMNO-PQRST-UVWXY’; // API token for AI
var tunnelUrl = ‘’; // Cloudflare tunnel URL
var endpoint = tunnelUrl + ‘/api/v1/workspace/’ + client + ‘/chat’;
var jwtToken = “LONGSTRINGOFNUMBERS”; // obtained from application in CF zero trust
// Define the query payload
var payload = {
“message”: message,
“mode”: “query”
};
// Set up the request options with JWT token and API token
var options = {
‘method’: ‘post’,
‘contentType’: ‘application/json’,
‘headers’: {
‘Authorization’: 'Bearer ’ + jwtToken, // JWT token for authentication
‘API-Token’: apiToken, // AI API token
‘User-Agent’: ‘Mozilla/5.0’
},
‘payload’: JSON.stringify(payload),
‘muteHttpExceptions’: true
};
try {
// Make the request to AI
var response = UrlFetchApp.fetch(endpoint, options);
// Log full response for debugging
Logger.log('Response Code: ' + response.getResponseCode());
Logger.log('Response Body: ' + response.getContentText());
if (response.getResponseCode() === 200) {
var jsonResponse = JSON.parse(response.getContentText());
return jsonResponse.message;
} else {
throw new Error('Request to AI failed with status: ' + response.getResponseCode());
}
} catch (error) {
Logger.log('Error: ’ + error.toString());
return 'Error: ’ + error.toString();
}
}