Search code examples
javascriptreactjsapiaxiosimgur

How do i make a GET requests from Imgur's API via Axios on my react app


I've tried everything,it keeps returning an error message

main.js?attr=_BODkjRO5QpCpDBDHmq3zW7ER-QQAJ8TUaG_zfoS-_UYoHvVr1lIpJQyTDNBAEyN:2605 GET https://api.imgur.com/3/image?query=cars 400

and

createError.js:16 Uncaught (in promise) Error: Request failed with status code 400
    at createError (createError.js:16)
    at settle (settle.js:17)
    at XMLHttpRequest.handleLoad (xhr.js:62)

It works with their GET gallery URL though, so I don't understand if the GET Image URL is broken.

My code:

const response = await axios.get( 'https://api.imgur.com/3/image' , {
  params: {query: text},
  headers: {
    Authorization: 'Client-ID {MY ACTUAL CLIENT ID}'
  }
})

console.log(response);


Solution

  • the api is like

    https://api.imgur.com/3/image/{imageID}
    

    and not

    https://api.imgur.com/3/image?query=cars
    

    maybe you are looking for something like this? https://api.imgur.com/endpoints/gallery#gallery-search