WDI-SEA / project-4-issues

Open an issue to receive help on project 4 issues
0 stars 0 forks source link

trying to return more than the max limit of results from api call #5

Closed paulinal3 closed 2 years ago

paulinal3 commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

MERN

What's the problem you're trying to solve?

The external api I'm using will only return a max of 100 results at a time. I guess less of an issue and more of a question, but is the only way to get more results to make multiple calls? But how would I add continually add that to the state each time? Or is that not possible?

Post any code you think might be relevant (one fenced block per file)

API Call

export const getNetflixVideos = () => {
    return axios({
        method: 'GET',
        url: `${rootAPI}?q=&cl=78&p=2&t=ns&st=adv`,
        headers: {
            'X-RapidAPI-Host': `${apiHost}`,
            'X-RapidAPI-Key': `${apiKey}`
        }
    })
}

Setting results to state

    const [netflixVids, setNetflixVids] = useState([])

    useEffect(() => {
        getNetflixVideos()
            .then(videos => {
                console.log('these are all the videos on US Netflix\n', videos.data)
                setNetflixVids(videos.data.ITEMS)
            })
            .catch(err => console.error)
    }, [])

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

N/A

What is your best guess as to the source of the problem?

The p= in the query represents the different page numbers so would I just have to use recursion increasing that number each time constantly making calls till the end results?

What things have you already tried to solve the problem?

Stack overflow is saying to use recursion but I only get 100 api calls a day and that would take about 50 calls to do...