Search code examples
reactjsaxiosyoutube-data-apihttp-status-code-400

ReactJS- Youtube Data API request error 400


I was using YouTube Data API. I did set up the parameters but when opening network from developer tools it is showing error: 'Required parameter:part'

axios code-

import axios from 'axios';

const KEY='[my key]'

export default axios.create({
    baseURL:'https://www.googleapis.com/youtube/v3',
    params:
    {
        part:'snippet',
        maxResults:5,
        key: KEY
    }
})

The callback function which is sending API request

termSearch= (term)=>
    {   
        console.log(term)
        youtube.get('/search',{
            params:
            {
                q:term
            }
        })

I expected to receive the JSON response but console is showing- Error:GET https://www.googleapis.com/youtube/v3/search?q=asdas 400


Solution

  • Looks like there is an open issue on Axios where request parameters are not getting merged with instance parameters. So your params object from your axios.create(...) are not being used properly in your callback.

    Maybe you could try downgrading Axios to version: 0.18.1 until a fix has been patched in? This seems to be the workaround used by others at this particular instance in time.

    Hopefully that helps!