Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

301
Vistas
Error: Request Failed with status code 400 - React - API Key

this is my code:

import "./styles.css";
import "mvp.css";
import { useState, useEffect } from "react";
import axios from "axios";

function Books() {
  const [book, setBook] = useState("");
  const [result, setResult] = useState([]);
  const [apiKey, setApiKey] = useState(
    ""
  );
  function handleChange(event) {
    const book = event.target.value;

    setBook(book);
  }

  function handleSubmit(event) {
    event.preventDefault();

    axios
      .get(
        "https://www.googleapis.com/books/v1/volumes?q=" +
          book +
          "&key=" +
          apiKey +
          "&maxResults=100"
      )
      .then((data) => {
        console.log(data);
      });
  }

  return (
    <div className="App">
      <h1>Search For A Book</h1>
      <form onSubmit={handleSubmit}>
        <div className="form-group">
          <input
            type="text"
            onChange={handleChange}
            className="input"
            placeholder="Search..."
          />
          <button type="submit" className="btn">
            Go!
          </button>
        </div>
      </form>
    </div>
  );
}

export default function App() {
  return <Books />;
}

Is anyone able to figure out why I am unable to get this to work? I keep getting a Request failed error and I am not sure what is going wrong. I have manually entered my url into the my browser such as this:

https://www.googleapis.com/books/v1/volumes?q=javascript&key=APIKEY

But when I do it through my code it is not working.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

As you can see, your url in axios is: https://www.googleapis.com/books/v1/volumes?q=javascript&key=apiKey&maxResults=100

So that why return http code 400, you should remove &maxResults=100

about 4 years ago · Juan Pablo Isaza Denunciar

0

maxResults should be less than <= 40 according to recommendation. Update the max result in code. It would work after that

about 4 years ago · Juan Pablo Isaza Denunciar

0

What's the erro message? If "API key not valid. Please pass a valid API key." u api key is wrong. This page will help you https://cloud.google.com/apis/design/errors

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda