Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Getting API authentication key error with PublicAPI

I'm new to the FetchAPAI. For my first API project, I'm currently using the ClimatIQ API and following the steps in their Quickstart guide. Even if I've already signed up and received an authentication key from them, I keep getting the ff error from them:

POST https://beta2.api.climatiq.io/estimate 400
{error: 'invalid_request', message: 'Error parsing the request body.'}

Take note in the guide, the code is in Curl, and I did my best trying to convert that code into a fetchAPI request on JavaScript.

const fetchData = async (url) => {
  await fetch(url, {
    method: "POST",
    headers: { Authorization: "Bearer MY_API_KEY" },
    data: {
      emission_factor: "electricity-energy_source_grid_mix",
      parameters: {
        energy: 4200,
        energy_unit: "kWh",
      },
    },
    //body: JSON.stringify(data),
  })
    .then((response) => response.json())
    .then((json) => console.log(json))
    .catch((err) => console.log(`Here's the error ${err}`));
};

fetchData("https://beta2.api.climatiq.io/estimate");

From time to time, it also shows a "header is not defined" even if I already put in the authentication key they gave me in the "MY_API_KEY" part of my codebase. Is this an error with their server?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try this:

const data = {
  emission_factor: "electricity-energy_source_grid_mix",
  parameters: {
    energy: 4200,
    energy_unit: "kWh",
  },
};

const fetchData = async(url) => {
  await fetch(url, {
      method: "POST",
      headers: {
        Authorization: "Bearer MY_API_KEY",
        "Content-Type": "application/json"
      },
      body: JSON.stringify(data)
    })
    .then((response) => response.json())
    .then((json) => console.log(json))
    .catch((err) => console.log(`Here's the error ${err}`));
};

fetchData("https://beta2.api.climatiq.io/estimate");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!