Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda