API Authentication error

Dear community,

non-technical person here - I am trying to fetch a list of image URLs from the API but am encountering an authentication error although I am sure I am providing the right API token and the correct Account ID. Error message:

"Exception: Request failed for https://api.cloudflare.com returned code 400. Truncated server response: {“success”:false,“errors”:[{“code”:10000,“message”:“Authentication error”}]} (use muteHttpExceptions option to examine full response)

listImagesV2 @ Code.gs:18"

This is the code I am using:

function listImagesV2() {
// Replace with your Cloudflare API Bearer token

// Replace with your Cloudflare account identifier

// Set the Cloudflare API URL for listing images V2
var apiUrl = “https://api.cloudflare.com/client/v4/accounts/” + accountIdentifier + “/images/v2”;

// Set up the request headers
var headers = {
“Authorization”: "Bearer " + bearerToken,
“Content-Type”: “application/json”,

// Make the API request to Cloudflare
var response = UrlFetchApp.fetch(apiUrl, {
method: “GET”,
headers: headers,

// Parse the JSON response
var responseData = JSON.parse(response.getContentText());

// Check if the request was successful
if (response.getResponseCode() === 200) {
// Extract the list of images from the responseData object
var imagesList = responseData.result;

// Create an HTML output with the list of image URLs
var htmlOutput = "<html><body><table>";
htmlOutput += "<tr><th>Original File Name</th><th>Image URL</th></tr>";

imagesList.forEach(function (image) {
  htmlOutput += "<tr><td>" + image.original_name + "</td><td>" + image.url + "</td></tr>";

htmlOutput += "</table></body></html>";

// Display the list in the browser
return HtmlService.createHtmlOutput(htmlOutput);

} else {
// Handle error response
var errorInfo = responseData.errors[0];
return "Error: Code " + errorInfo.code + ", Message: " + errorInfo.message;

Does anyone have any hints on what I am doing wrong? Thank you very much!

Sorry for the issues with this @vasco, are you still encountering this issue? (I took some steps to try & correct, not sure if they were productive or not).

If you keep getting the error, can you create an Account ticket and share your ticket number here? You can open an Account ticket here, https://dash.cloudflare.com/?to=/:account/support