I am developing a flight search app using that interacts with the Priceline API through RapidAPI
. The problem is that the API is not returning any flight results. I am also receiving a specific error message in the JSON response.
Code doing the API Call:
import Foundation
class FlightService {
static let shared = FlightService()
private init() {}
private func createURLRequest(endpoint: String, parameters: [String: String]?) -> URLRequest? {
var components = URLComponents(string: "https://priceline-com2.p.rapidapi.com/(endpoint)")
if let params = parameters {
components?.queryItems = params.map { URLQueryItem(name: $0.key, value: $0.value) }
}
guard let url = components?.url else { return nil }
var request = URLRequest(url: url)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
request.addValue("xxxxxxxxxxxxxxxx", forHTTPHeaderField: "X-RapidAPI-Key")
request.addValue("priceline-com2.p.rapidapi.com", forHTTPHeaderField: "X-RapidAPI-Host")
return request
}
func searchFlightsRoundTrip(origin: String, destination: String, departureDate: String, returnDate: String, passengers: Int, classType: String) async throws -> [Flight] {
let endpoint = "flights/search-roundtrip"
let parameters = [
"originAirportCode": origin,
"destinationAirportCode": destination,
"departureDate": departureDate,
"returnDate": returnDate,
"numberOfPassengers": String(passengers),
"classType": classType
]
print("Enviando parámetros a la API: (parameters)")
guard let request = createURLRequest(endpoint: endpoint, parameters: parameters) else {
throw URLError(.badURL)
}
let (data, response) = try await URLSession.shared.data(for: request)
if let httpResponse = response as? HTTPURLResponse {
print("HTTP Status Code: (httpResponse.statusCode)")
}
if let jsonString = String(data: data, encoding: .utf8) {
print("Response JSON: (jsonString)")
}
do {
let flightResponse = try JSONDecoder().decode(FlightResponse.self, from: data)
if let flights = flightResponse.data?.searchItems {
print("Flights received: (flights.count)")
return flights
} else {
print("No flights found in the response.")
return []
}
} catch {
print("Error decoding flight data: (error)")
throw error
}
}
}
Request I am sending to the API:
{
"originAirportCode": "MAD",
"destinationAirportCode": "LON",
"departureDate": "2024-09-30",
"returnDate": "2024-10-15",
"numberOfPassengers": "2",
"classType": "ECO"
}
The API Response with the following JSON, which seems to indicate an error:
{
"data": {
"isFireFly": null,
"airline": null,
"airport": null,
"listings": null,
"expressDeal": null,
"filterDefaults": null,
"listingsMetaData": null,
"travelInsurance": null,
"error": {
"code": null,
"desc": null,
"message": "Error while invoking the QueryExecutor.search Operation for component FLY in Error: com.priceline.usp.search.exception.QueryExecutorException: QueryExecutorService.search while calling component FLY, resulted in Error : No Itineraries Found for Given Request , StatusCode: ."
},
"displayableCarriers": null,
"expressDealsCandidates": null,
"brandReference": null
},
"meta": {
"currentPage": 1,
"limit": 0,
"totalRecords": 0,
"totalPage": 0
},
"status": true,
"message": "Successful"
}
Here is the output from the console:
API: ["destinationAirportCode": "LON", "originAirportCode": "MAD", "numberOfPassengers": "2", "classType": "ECO", "departureDate": "2024-09-30", "returnDate": "2024-10-15"]
HTTP Status Code: 200
Response JSON: {"data":{"isFireFly":null,"airline":null,"airport":null,"listings":null,"expressDeal":null,"filterDefaults":null,"listingsMetaData":null,"travelInsurance":null,"error":{"code":null,"desc":null,"message":"Error while invoking the QueryExecutor.search Operation for component FLY in Error: com.priceline.usp.search.exception.QueryExecutorException: QueryExecutorService.search while calling component FLY, resulted in Error : No Itineraries Found for Given Request , StatusCode: ."},"displayableCarriers":null,"expressDealsCandidates":null,"brandReference":null},"meta":{"currentPage":1,"limit":0,"totalRecords":0,"totalPage":0},"status":true,"message":"Successful"}
No flights found in the response.
Problem:
Even though I am receiving a 200 OK status from the API, the response data contains no flight itineraries.
The error message in the response is vague: No Itineraries Found for Given Request.
Questions:
- Why am I not getting any flight results from the API, and what does the error
No Itineraries Found for Given Request
mean in this context? - Are there any specific changes I need to make to my request parameters to resolve this issue?
1