ravipandhi
ravipandhi

Reputation: 49

Fetching per segment price from Google QPX Express API

Using this url: https://qpx-express-demo.itasoftware.com/ I am making a request to get flight availability from BOM to NYC on a future date. The JSON response that i receive :

Formatted Response: Solution# 1 Sale Price: INR31803 Slice 0 KU 302 BOM 2016-01-29T05:50+05:30 KWI 2016-01-29T07:50+03:00 KU 117 KWI 2016-01-29T09:55+03:00 JFK 2016-01-29T16:20-05:00

Unformatted Response:

{
    "kind": "qpxexpress#tripOption",
    "saleTotal": "INR31803",
    "id": "5WAPnfYj8mARdie1jBKphP002",
    "slice": [
     {
      "kind": "qpxexpress#sliceInfo",
      "duration": 1260,
      "segment": [
       {
        "kind": "qpxexpress#segmentInfo",
        "duration": 270,
        "flight": {
         "carrier": "KU",
         "number": "302"
        },
        "id": "G9ieitLhcbGEpU6u",
        "cabin": "COACH",
        "bookingCode": "H",
        "bookingCodeCount": 9,
        "marriedSegmentGroup": "0",
        "leg": [
         {
          "kind": "qpxexpress#legInfo",
          "id": "LRlNO3Gw0UX8y69J",
          "aircraft": "777",
          "arrivalTime": "2016-01-29T07:50+03:00",
          "departureTime": "2016-01-29T05:50+05:30",
          "origin": "BOM",
          "destination": "KWI",
          "originTerminal": "2",
          "destinationTerminal": "M",
          "duration": 270,
          "mileage": 1713,
          "meal": "Breakfast",
          "secure": true
         }
        ],
        "connectionDuration": 125
       },
       {
        "kind": "qpxexpress#segmentInfo",
        "duration": 865,
        "flight": {
         "carrier": "KU",
         "number": "117"
        },
        "id": "GBan4WxY2pcKVHbu",
        "cabin": "COACH",
        "bookingCode": "H",
        "bookingCodeCount": 9,
        "marriedSegmentGroup": "1",
        "leg": [
         {
          "kind": "qpxexpress#legInfo",
          "id": "L9pmI3XsVZSBhZah",
          "aircraft": "777",
          "arrivalTime": "2016-01-29T16:20-05:00",
          "departureTime": "2016-01-29T09:55+03:00",
          "origin": "KWI",
          "destination": "JFK",
          "originTerminal": "M",
          "destinationTerminal": "4",
          "duration": 865,
          "mileage": 6336,
          "meal": "Meal",
          "secure": true
         }
        ]
       }
      ]
     }
    ],
    "pricing": [
     {
      "kind": "qpxexpress#pricingInfo",
      "fare": [
       {
        "kind": "qpxexpress#fareInfo",
        "id": "A80Fm/pw8E5LRH33c8hjZw/s+BTPU4IxJWOlGXyM1SLM",
        "carrier": "KU",
        "origin": "BOM",
        "destination": "NYC",
        "basisCode": "HLOWIN1"
       }
      ],
      "segmentPricing": [
       {
        "kind": "qpxexpress#segmentPricing",
        "fareId": "A80Fm/pw8E5LRH33c8hjZw/s+BTPU4IxJWOlGXyM1SLM",
        "segmentId": "G9ieitLhcbGEpU6u"
       },
       {
        "kind": "qpxexpress#segmentPricing",
        "fareId": "A80Fm/pw8E5LRH33c8hjZw/s+BTPU4IxJWOlGXyM1SLM",
        "segmentId": "GBan4WxY2pcKVHbu"
       }
      ],
      "baseFareTotal": "INR26460",
      "saleFareTotal": "INR26460",
      "saleTaxTotal": "INR5343",
      "saleTotal": "INR31803",
      "passengers": {
       "kind": "qpxexpress#passengerCounts",
       "adultCount": 1
      },
      "tax": [
       {
        "kind": "qpxexpress#taxInfo",
        "id": "JN_004",
        "chargeType": "GOVERNMENT",
        "code": "JN",
        "country": "IN",
        "salePrice": "INR1482"
       },
       {
        "kind": "qpxexpress#taxInfo",
        "id": "F2_001",
        "chargeType": "GOVERNMENT",
        "code": "F2",
        "country": "IN",
        "salePrice": "INR53"
       },
       {
        "kind": "qpxexpress#taxInfo",
        "id": "IN",
        "chargeType": "GOVERNMENT",
        "code": "IN",
        "country": "IN",
        "salePrice": "INR627"
       },
       {
        "kind": "qpxexpress#taxInfo",
        "id": "YM_001",
        "chargeType": "GOVERNMENT",
        "code": "YM",
        "country": "IN",
        "salePrice": "INR687"
       },
       {
        "kind": "qpxexpress#taxInfo",
        "id": "WO_001",
        "chargeType": "GOVERNMENT",
        "code": "WO",
        "country": "IN",
        "salePrice": "INR149"
       },
       {
        "kind": "qpxexpress#taxInfo",
        "id": "US_002",
        "chargeType": "GOVERNMENT",
        "code": "US",
        "country": "US",
        "salePrice": "INR1190"
       },
       {
        "kind": "qpxexpress#taxInfo",
        "id": "YX_001",
        "chargeType": "GOVERNMENT",
        "code": "YX",
        "country": "KW",
        "salePrice": "INR54"
       },
       {
        "kind": "qpxexpress#taxInfo",
        "id": "YC",
        "chargeType": "GOVERNMENT",
        "code": "YC",
        "country": "US",
        "salePrice": "INR368"
       },
       {
        "kind": "qpxexpress#taxInfo",
        "id": "XY",
        "chargeType": "GOVERNMENT",
        "code": "XY",
        "country": "US",
        "salePrice": "INR468"
       },
       {
        "kind": "qpxexpress#taxInfo",
        "id": "XA",
        "chargeType": "GOVERNMENT",
        "code": "XA",
        "country": "US",
        "salePrice": "INR265"
       }
      ],
      "fareCalculation": "BOM KU X/KWI KU NYC 397.64HLOWIN1 NUC 397.64 END ROE 66.541160 FARE INR 26460 XT 53F2 627IN 1482JN 149WO 687YM 54YX 368YC 468XY 265XA 1190US",
      "latestTicketingTime": "2016-01-28T19:19-05:00",
      "ptc": "ADT",
      "refundable": true
     }

From the response it is inferred that there are two segments, one with KU 302 and other with KU 117. How can i get per segment (per flight) info from the response?

Upvotes: 0

Views: 668

Answers (1)

Stefano d'Antonio
Stefano d'Antonio

Reputation: 6152

I'm using the APIs in C#, if you install the Json.NET NuGet package, you can then get the response and deserialize it with:

JsonConvert.DeserializeObject<Response>(jsonString);

To build the Response object you can use an online Json to C# class builder (Google it and you'll find it immediately), or you can use dynamic objects.

Once you have the deserialized responde, you can just use LINQ to filter the informations:

from r in response where <filters> select r.segment // Or specific data.

All this assuming you want to use C#.

Upvotes: 1

Related Questions