Recipe by API-Ninjas

פרמיום
על ידי API Ninjas Team | מְעוּדכָּן לפני 23 ימים | Food
פּוֹפּוּלָרִיוּת

9.6 / 10

חֶבִיוֹן

602ms

רמת שירות

92%

Health Check

N/A

חזרה לכל הדיונים

Offset not working (not returning more than 10 results)

Rapid account: Lee 140794
lee140794
2 years ago

I want to get more than 10 results. I set the offset to 50 so I can get 50 results but it still returns only 10.
I am using angular.

The documentation also says “use the offset parameter to offset results in multiple API calls”.

How do I make multiple API calls?

This is what my code looks like:

private httpHeaders: HttpHeaders = new HttpHeaders({
‘X-RapidAPI-Key’: ‘my-key’,
‘X-RapidAPI-Host’: ‘recipe-by-api-ninjas.p.rapidapi.com
});

public searchText: string = '';

public getRecipes(): void {
let httpParams: HttpParams = new HttpParams().set('query', this.searchText);
httpParams.set('offset', 50);
	
this.http
  .get<any>(`https://recipe-by-api-ninjas.p.rapidapi.com/v1/recipe`, {
    headers: this.httpHeaders,
    params: httpParams
  })
  .subscribe(data => {
    console.log(data);
  });

}

Rapid account: Lee 140794
lee140794 Commented 2 years ago

Hi calorieninjas!
Thank you for your response but I am still getting the same 10 results:
Here is my code when I make multiple api calls. I set the offset to 0 then to 10 but still get the same results:

let httpParams: HttpParams = new HttpParams().set(‘query’, ‘chicken’);

httpParams.set('offset',  0); // ZERO HERE
this.http.get<RecipeAPI>(`https://recipe-by-api-ninjas.p.rapidapi.com/v1/recipe`, {
    headers: this.recipeHttpHeaders,
    params: httpParams
  }).subscribe(data => console.log(data));

httpParams.set('offset', 10); // TEN HERE
this.http.get<RecipeAPI>(`https://recipe-by-api-ninjas.p.rapidapi.com/v1/recipe`, {
    headers: this.recipeHttpHeaders,
    params: httpParams
  }).subscribe(data => console.log(data));
Rapid account: Calorieninjas
calorieninjas Commented 2 years ago

The offset parameter does not change the maximum number of results returned (which is 10), it just offsets them. For example, if a query has 50 total results, you can set offset to 0 for first 10 results, set the offset to 10 for results 10-20, and so on.

By ‘making multiple API calls’, just make multiple http.get requests with different offsets.

Cheers

הצטרף לדיון - הוסף תגובה למטה:

התחבר / הירשם כדי לפרסם תגובות חדשות