My API returns paginated data, especially the latest_prices endpoint. The latest_connections endpoint usually only returns one page. I have put that in the OpenAPI spec, I have even provided an example:
openapi: 3.0.0
info:
title: xxx API
version: 2
description: xxx API V2
servers:
- url: https://backend.xxx.ch/
paths:
/api/xxx/v2/latest_connection:
get:
operationId: getLatestConnectionListView
summary: Get latest connection
description: >
This endpoint takes a constant query_id (ID=7) and a desired departure date to return a list of possible
connections.
tags:
- latest_connection
parameters:
- name: query_id
in: query
required: true
schema:
type: integer
default: 7
description: Constant query_id parameter with a default value of 7.
- name: departure
in: query
required: true
schema:
type: string
format: date
description: Desired departure date in YYYY-MM-DD format.
responses:
"200":
description: A list of possible connections based on the provided query_id and departure date.
content:
application/json:
schema:
type: object
properties:
current_page:
type: integer
next_page:
type: "null"
description: The pointer to the next page for paginated data. If "null", the end has been reached.
page_size:
type: integer
previous_page:
type: "null"
results:
type: array
items:
type: object
properties:
changes:
type: integer
created_at:
type: string
format: date-time
departure:
type: string
format: date-time
desired_dst_canonical_name:
type: string
desired_dst_de:
type: string
desired_src_canonical_name:
type: string
desired_src_de:
type: string
duration:
type: string
id:
type: integer
traintypes:
type: string
updated_at:
type: string
format: date-time
via:
type: "null"
total_count:
type: integer
total_pages:
type: integer
/api/xxx/v2/latest_prices:
get:
operationId: getLatestPricesListView
summary: Get latest prices
description: >
Takes a connection_id and returns a paginated list of offers with associated prices. Clients should monitor the
`next_page` attribute in the response to determine if additional data is available and to fetch subsequent
pages. Ignoring this attribute may result in incomplete data retrieval.
tags:
- latest_prices
parameters:
- name: connection_id
in: query
required: true
schema:
type: integer
description: ID of the connection for which prices are being queried.
- name: page
in: query
required: true
schema:
type: integer
description: the page number to fetch
default: 1
- name: page_size
in: query
required: true
schema:
type: integer
description: the number of items per page to fetch
default: 50
responses:
"200":
description: A list of offers with associated prices for the given connection ID.
content:
application/json:
schema:
type: object
properties:
current_page:
type: integer
next_page:
type: string
nullable: true
description: >
Provides the URL for the next page of results. This field is `null` if there are no more pages. Always check this
attribute to ensure complete data collection.
page_size:
type: integer
previous_page:
type: string
nullable: true
results:
type: array
items:
type: object
properties:
crawler_engine:
type: string
created_at:
type: string
format: date-time
gender:
type: string
id:
type: integer
price:
type: integer
price_currency:
type: string
price_type:
type: string
seat_type:
type: string
subscription_card:
type: string
description: Information about the subscription / discount card to which the price is applying
updated_at:
type: string
format: date-time
vendor_link:
type: string
format: uri
total_count:
type: integer
total_pages:
type: integer
example:
current_page: 1
next_page: "/api/xxx/v2/latest_prices?page=2&page_size=10&connection_id=1244872"
page_size: 10
previous_page: null
results: [...]
total_count: 100
total_pages: 10
Also, in the instructions, I have explicitly told to fetch all pages:
When interacting with the API for fetching both connections and prices, if the initial response has a
next_page
attribute that is not null, indicating more pages of data are available, the GPT will repeatedly call the API, passing thenext_page
value each time, until it fetches all pages. This process is essential for ensuring that all available information is collected before presenting the findings to the user. This meticulous attention to fetching all paginated data ensures users receive comprehensive and detailed responses.
Still, the GPT completely ignores this. I only ever fetches the first page. What am I doing wrong?