amadeus4dev-examples / amadeus-php

PHP library for the Amadeus Self-Service APIs
https://amadeus4dev-examples.github.io/amadeus-php/
MIT License
11 stars 13 forks source link

Response returning incomplete Data #97

Closed JayRSG closed 1 year ago

JayRSG commented 1 year ago

Calling the getFlightOffers endpoint through

$flightOffers = $this->amadeus->getShopping()->getFlightOffers()->get($data);

Steps to Reproduce

  1. I have created a laravel project, added this package, created a route and associated a controller with it.
  2. Configured postman to call the route
  3. Received the response

Expected Behavior: Expecting Amadeus FlightOffers data according to the API specification

Actual Behavior: Receiving partial data. { "data": [ { "lastTicketingDateTime": "2023-06-05" }, { "lastTicketingDateTime": "2023-05-31" }, { "lastTicketingDateTime": "2023-05-31" } ] }

Request payload: originLocationCode:SYD destinationLocationCode:BYK departureDate:2023-06-05 adults:1 max:10

Stable Behavior? It is consistently generating the same result every time

Versions

PHP version: 7.4.16 Laravel version: 8.75 postman: v10.14

Checklist

amadeus-php version: 0.3.0

JayRSG commented 1 year ago

@tsolakoua @xianqiliu I will be glad if you kindly advise me a solution for this problem that I am facing right now! I have found out its the src/resources/Resource.php: fromArray(Response $response, string $class) method which is where the problem is originating.

The $response has got the complete response as of the Amadeus Self Service APi endpoint for FlightOffersSearch would return, but the implementation in the said method is not being able to handle the reponse properly and the resource object being returned is returning the data I have mentioned in my Issue #97

Eagerly waiting for your response. Thanks.

xianqiliu commented 1 year ago

@tsolakoua @xianqiliu I will be glad if you kindly advise me a solution for this problem that I am facing right now! I have found out its the src/resources/Resource.php: fromArray(Response $response, string $class) method which is where the problem is originating.

The $response has got the complete response as of the Amadeus Self Service APi endpoint for FlightOffersSearch would return, but the implementation in the said method is not being able to handle the reponse properly and the resource object being returned is returning the data I have mentioned in my Issue #97

Eagerly waiting for your response. Thanks.

@JayRSG Hey, the reason why the returned data is incomplete may be that the sdk's FlightOffer resource is not totally matching with the FlightOffer object in Amadeus Flight offer search API response model. And the way you use the sdk $flightOffers = $this->amadeus ->getShopping()->getFlightOffers()->get($data);, which will only return row data matching in FlightOffer resource in this sdk. So if you want the full data, you can create a PR to update the "FlightOffer" resource in this sdk to exactly match the official Amadeus "FlightOffer" object in the API response. Or you can directly use this sdk to get data, as follows:

// Make a GET request only using path
$amadeus->getClient()->getWithOnlyPath("/v1/airport/direct-destinations?departureAirportCode=MAD");

// Make a GET request using path and passed parameters
$amadeus->getClient()->getWithArrayParams("/v1/airport/direct-destinations", ["departureAirportCode" => "MAD"]);

// Make a POST request using path and passed body
$amadeus->getClient()->postWithStringBody("/v1/shopping/availability/flight-availabilities", $body);
tsolakoua commented 1 year ago

Since there is a working solution provided by @xianqiliu, closing this issue.