Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to get all movies from the API based on search term but at the moment the API returns only the first 10 movies.

The api has a page number parameter that returns the specific page number but I want to get all movies.

<pre><pre>async getResults(page = 1) {
       
        try {

            const res = await axios(`${proxy}http://www.omdbapi.com/? 
            apikey=${apiKey}&s=${this.query}&type=movie&page=${page}`);
            this.result = res.data;
            this.page = page;

            

        } catch (error) {
            console.log(error);
        }

    }
}


What I have tried:

My code below only returns the first 10 movies but I want to get all movies.
<pre><pre><pre>async getResults(page = 1) {
       
        try {

            const res = await axios(`${proxy}http://www.omdbapi.com/? 
            apikey=${apiKey}&s=${this.query}&type=movie&page=${page}`);
            this.result = res.data;
            this.page = page;

            

        } catch (error) {
            console.log(error);
        }

    }
}
Posted
Updated 8-Nov-20 0:42am
Comments
Richard MacCutchan 7-Nov-20 15:23pm    
Well you only ask for page=1. Maybe you should request some other pages.
hamid1_2 7-Nov-20 16:48pm    
How do I return all movies from all pages based on search term
Dave Kreskowiak 7-Nov-20 22:45pm    
How about you ask the people who wrote the API?

A similar discussion here[^]:
Quote:
You can't get all the movies from OMDb API, even if you use * it will return an error Too many results.

You can return multiple results using s parameter. Look at the code sample below using jQuery.
A snippet:
HTML
<!DOCTYPE html>
<html>
  <head>
    <title>Ajax Request</title>
  </head>
  <body>

    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
      // Check your browser console to view the result.
      $.get("http://www.omdbapi.com/?s=inception&apikey=[yourkey]", function(data) {
        console.table(data);
      });
    </script>
  </body>
</html>
 
Share this answer
 
Hi Sandeep

When you pass the s parameter it only returns 10 first movies. However I want to return all movies.
 
Share this answer
 
Comments
h311o 8-Nov-20 7:05am    
@hamid1_2 you can leave a comment instead of making another solution :)
hamid1_2 8-Nov-20 11:38am    
sorry i'm new to this site.
h311o 8-Nov-20 21:06pm    
That's okay :D
Richard MacCutchan 8-Nov-20 7:16am    
Go to OMDb API - The Open Movie Database[^] and study the API documentation.
hamid1_2 8-Nov-20 11:38am    
I have looked up the documentation but couldn't find what i was looking for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900