Recipe by API-Ninjas

FREEMIUM
От API Ninjas Team | Обновлено vor 21 Tagen | Food
Популярность

9.6 / 10

Задержка

600ms

Уровень обслуживания

92%

Health Check

N/A

Назад ко всем обсуждениям

Offset not working (not returning more than 10 results)

Rapid account: Lee 140794
lee140794
vor 2 Jahren

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 vor 2 Jahren

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 vor 2 Jahren

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

Присоединяйтесь к обсуждению – добавьте комментарий ниже:

Войдите / Зарегистрируйтесь, чтобы публиковать новые комментарии