Cannot send data to Influx DB

I have created a worker on cloudflare that is supposed to recieve an object and send it to my influx DB. The problem here is whenever I run the request separately from cloudflare that is on postman or using the curl command on the terminal. It returns a status code of 204 which is what I want.

However when I run the same fetch request on a clouflare worker it hits me with that 403 Unauthorized error. What could be the problem.

Here is the cloudlfare worker js code::

async fetch(request, env, ctx) {
const token = env.INFLUX_TOKEN_C;
const org = env.INFLUX_ORG_C;
const bucket = env.INFLUX_BUCKET_C;
const url = env.INFLUX_URL_C;

if (request.method === 'POST') {
  try {
    const response = await request.json();
      //env variables include our influxDB url with /api/v2/write endpoint and bucket
    const influxUrl = `${url}?org=${org}&bucket=${bucket}&precision=ns`;
      //We configure our payload using line protocol format
    const influxPayload = `${response.measurement},user_id=${response.user_id} path="${response.path}",max_depth=${response.max_depth},page_dimensions="${response.page_dimensions}"`;
    
      // We'll use an API enpoint by appending /api/v2/write to send data to influx DB
    const influxResponse = await fetch(influxUrl, {
      method: 'POST',
      headers: {
        'Authorization': `Token ${token}`,
        'Content-Type': 'text/plain',
      },
      body: influxPayload,
    });

    if (!influxResponse.ok) {
      const responseBody = await influxResponse.text();
      console.error('InfluxDB response:', influxResponse.status, responseBody);
      throw new Error('Failed to send data to InfluxDB');
    }

    return new Response('Success', { status: 200 });
  } catch (error) {
    return new Response(`Error: ${error.message}`, { status: 500 });
  }
} else {
  return new Response('Method not allowed', { status: 405 });
}

},
};