azure Stream analytics isfirst and last query - azure-stream-analytics

I have the payload something like below. I need to get the first distinct batch values for every 1 minute period. Please let me know how to achieve this in stream analytics using isfirst and lag or last
Output like:
BATCH=01,"2015-01-01T00:00:01.0000000Z"
BATCH=02,"2015-01-01T00:00:03.0000000Z"
BATCH=03,"2015-01-01T00:00:06.0000000Z"
BATCH=01,"2015-01-01T00:00:14.0000000Z"
BATCH=02,"2015-01-01T00:00:18.0000000Z"
BATCH=03,"2015-01-01T00:00:22.0000000Z"
BATCH=01,"2015-01-01T00:00:27.0000000Z"
BATCH=01,"2015-01-01T00:00:31.0000000Z"
Pay Load:
[{
"Payload": {
"Make": "BATCH1",
"VAL": "01",
"TS": "2015-01-01T00:00:01.0000000Z"
}
},
{
"Payload": {
"Make": "BATCH1",
"VAL": "01",
"TS": "2015-01-01T00:00:02.0000000Z"
}
},
{
"Payload": {
"Make": "BATCH1",
"VAL": "02",
"TS": "2015-01-01T00:00:03.0000000Z"
}
},
{
"Payload": {
"Make": "BATCH1",
"VAL": "02",
"TS": "2015-01-01T00:00:04.0000000Z"
}
},
{
"Payload": {
"Make": "BATCH1",
"VAL": "02",
"TS": "2015-01-01T00:00:05.0000000Z"
}
},
{"Payload": {
"Make": "BATCH1",
"VAL": "03",
"TS": "2015-01-01T00:00:06.0000000Z"
}
},
{"Payload": {
"Make": "BATCH1",
"VAL": "03",
"TS": "2015-01-01T00:00:07.0000000Z"
}
},
{"Payload": {
"Make": "BATCH1",
"VAL": "03",
"TS": "2015-01-01T00:00:10.0000000Z"
}
},
{"Payload": {
"Make": "BATCH1",
"VAL": "03",
"TS": "2015-01-01T00:00:11.0000000Z"
}
},
{"Payload": {
"Make": "BATCH1",
"VAL": "03",
"TS": "2015-01-01T00:00:12.0000000Z"
}
},
{"Payload": {
"Make": "BATCH2",
"VAL": "01",
"TS": "2015-01-01T00:00:13.0000000Z"
}
},
{"Payload": {
"Make": "BATCH2",
"VAL": "01",
"TS": "2015-01-01T00:00:14.0000000Z"
}
},
{"Payload": {
"Make": "BATCH2",
"VAL": "01",
"TS": "2015-01-01T00:00:15.0000000Z"
}
},
{"Payload": {
"Make": "BATCH2",
"VAL": "01",
"TS": "2015-01-01T00:00:16.0000000Z"
}
},
{"Payload": {
"Make": "BATCH2",
"VAL": "01",
"TS": "2015-01-01T00:00:17.0000000Z"
}
},
{"Payload": {
"Make": "BATCH2",
"VAL": "02",
"TS": "2015-01-01T00:00:18.0000000Z"
}
},
{"Payload": {
"Make": "BATCH2",
"VAL": "02",
"TS": "2015-01-01T00:00:20.0000000Z"
}
},
{"Payload": {
"Make": "BATCH2",
"VAL": "02",
"TS": "2015-01-01T00:00:21.0000000Z"
}
},
{"Payload": {
"Make": "BATCH3",
"VAL": "02",
"TS": "2015-01-01T00:00:22.0000000Z"
}
},
{"Payload": {
"Make": "BATCH3",
"VAL": "02",
"TS": "2015-01-01T00:00:23.0000000Z"
}
},
{"Payload": {
"Make": "BATCH3",
"VAL": "02",
"TS": "2015-01-01T00:00:24.0000000Z"
}
},
{"Payload": {
"Make": "BATCH3",
"VAL": "02",
"TS": "2015-01-01T00:00:25.0000000Z"
}
},
{"Payload": {
"Make": "BATCH3",
"VAL": "02",
"TS": "2015-01-01T00:00:26.0000000Z"
}
},
{"Payload": {
"Make": "BATCH4",
"VAL": "01",
"TS": "2015-01-01T00:00:27.0000000Z"
}
},
{"Payload": {
"Make": "BATCH4",
"VAL": "01",
"TS": "2015-01-01T00:00:28.0000000Z"
}
},
{"Payload": {
"Make": "BATCH4",
"VAL": "01",
"TS": "2015-01-01T00:00:29.0000000Z"
}
},
{"Payload": {
"Make": "BATCH4",
"VAL": "01",
"TS": "2015-01-01T00:00:30.0000000Z"
}
},
{"Payload": {
"Make": "BATCH5",
"VAL": "01",
"TS": "2015-01-01T00:00:31.0000000Z"
}
}
]

I tried to summarize your requirement as below:
Example input,in a minute window there can be multiple VAL changes for each batch ID:
Make:batch1,Val:01, Make:batch1,val:01, Make:batch1,val:02,
Make:batch1,val:02 ×××××××××××× Make:batch2,val:01,
Make:batch2,val:01, Xxxxxxxxxx
Desired output,only val for every batch changes and no duplicates:
Make:batch1,val:01 Make:batch1,val:02 Make:batch2,val:01
Answer is divided into 2 parts:
1.Collect data in a static period, you could use built-in Tumbling Window function as below:
2.No built-in ASA function like distinct to filter the duplicate.I'd suggest you using GROUP BY, MAX,ASA UDF(link) to approaching your result.
SQL:
SELECT g.Payload.Make,g.Payload.VAL,max(udf.convertdate(g.Payload.TS)) as TS
FROM geoinput g TIMESTAMP BY g.Payload.TS
GROUP BY g.Payload.Make,g.Payload.VAL, TumblingWindow(Duration(minute, 1))
Test output:
BTW,i just use below code inside UDF
var date = new Date(datetime);
return date.getTime();
Another workaround,you could collect all the data during 1 minute then use Azure Function as Output. In the Azure Function, you could process data as you want. Such as use JSON object to store the data.Key-Value structure could filter duplicate rows.

Related

how to solve this error in mongodb aggregation: TypeError: ({$unwind:{path:"$tags", preserveNullAndEmptyArrays:true}}) is not iterable :

i have a collection
[{
"_id": {"$oid": "63873b95c7e956270e734f3c"},
"employeeId": "emp1",
"users": [{"name": "Allen","registered": true},
{"name": "Henry","registered": true},
{"name": "Adam","registered": false}],
"tags": ["good","excellent","average"]
},{
"_id": {"$oid": "63873c05c7e956270e734f3d"},
"employeeId": "emp2",
"users": [{"name": "Federick","registered": false},
{"name": "Mary","registered": true},
{"name": "Sam","registered": false} ],
"tags": ["poor","excellent", "good"]}
,{
"_id": {"$oid": "63873c1fc7e956270e734f3e"},
"employeeId": "emp3",
"users": [ {"name": "john", "registered": true},
{"name": "jack","registered": true},
{"name": "elle", "registered": false } ],
"tags": ["very good", "excellent", "good" ]}]
i am trying to groupby tags and employee with count of employees under each tag,expected output is
i am getting the correct output by python code which is
pipeline = [{"$unwind":"$users"},{"$match":{"users.registered":True}},
{"$unwind":"$tags"},
{
"$group": {
"_id": "$tags","employees":{"$push": {"employeeId":"$employeeId"}},
"employees" : { "$addToSet" : "$employeeId" },
"count": {
"$sum": 1
}
}
},
{"$project":{"_id":1,"employees":1,"size":{"$size":"$employees"}}},
{"$sort" : { "size": -1 } },
]
rec = db.ratings.aggregate(pipeline)
but its giving error in mongoshell
Is this what you want?
db.collection.aggregate([
{
"$unwind": "$tags"
},
{
"$group": {
"_id": "$tags",
"employees": {
"$push": "$employeeId"
}
}
},
{
"$project": {
"_id": 1,
"employees": 1,
"size": {
"$size": "$employees"
}
}
},
{
"$sort": {
"size": -1
}
}
])
See how it works on the playground example

pass value from different Collection inside subquery in Match operation in Mongodb

I have 2 collection: Company and Stores. I used $lookup on Store collection using the storeIds on Company collection. I need to pass 'Company.Year' value to Stores.Statuses.Year inside $Match operator. Any help is appreciated.
Company: [
{
"_id": {
"$oid": "1388445c0000000000000001"
},
"name": "Company A",
"year": 2022,
"storeIds": [
{
"$oid": "1388445c0000000000000011"
},
{
"$oid": "1388445c0000000000000012"
}
]
}
]
Store: [
{
"_id": {
"$oid": "1388445c0000000000000011"
},
"name": "Store A",
"statuses": [
{
"year": 2021,
"status": "pending"
},
{
"year": 2022,
"status": "review"
}
]
}
]
Output: [
{
"_id": {
"$oid": "1388445c0000000000000001"
},
"name": "Company A",
"year": 2022,
"storeIds": [
{
"$oid": "1388445c0000000000000011"
}
],
"statuses": [
{
"year": 2022,--->How to pass company.year value instead of hard-coded value(2022).
"status": "review"
}
]
}
]

Is it correct to see a different cabin value aside that passed in the get FlightOffers APi as travelerClass?

From the documentation of the Get Route for the flight offers Api, I can add travelerClass as a filter to make a request. If I add say travelerClass as ECONOMY?
I expect to see only offers with ECONOMY. However I see that within the fareDetailsBySegment section in the result, I see that some Offers have their cabin values as other than ECONOMY. I see some with value of BUSINESS while others as PREMIUM_ECONOMY.
Is this proper?
My Concern
I want to be able to get all bookings that where ECONOMY based only. So I need to be sure that the flight offers returned in the first place are strictly limited by the travelerClass.
I will appreciate any clarity on the this issue. Also if there is a better way to go about this concern above, it will be most appreciated.
An example of my request is below:
Amadeus.shopping.flightOffersSearch.get({
originLocationCode: 'SYD',
destinationLocationCode: 'BKK',
departureDate: '2022-11-01',
adults: '1',
travelClass: 'ECONOMY'
}).then(...)
Offer with BUSINESS instead of ECONOMY
{
"type": "flight-offer",
"id": "22",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"oneWay": false,
"lastTicketingDate": "2022-11-01",
"numberOfBookableSeats": 6,
"itineraries": [
{
"duration": "PT28H20M",
"segments": [
{
"departure": {
"iataCode": "SYD",
"terminal": "1",
"at": "2022-11-01T12:00:00"
},
"arrival": {
"iataCode": "PVG",
"terminal": "2",
"at": "2022-11-01T19:30:00"
},
"carrierCode": "MU",
"number": "562",
"aircraft": {
"code": "77W"
},
"operating": {
"carrierCode": "MU"
},
"duration": "PT10H30M",
"id": "13",
"numberOfStops": 0,
"blacklistedInEU": false
},
{
"departure": {
"iataCode": "PVG",
"terminal": "1",
"at": "2022-11-02T08:45:00"
},
"arrival": {
"iataCode": "BKK",
"at": "2022-11-02T12:20:00"
},
"carrierCode": "MU",
"number": "541",
"aircraft": {
"code": "320"
},
"operating": {
"carrierCode": "MU"
},
"duration": "PT4H35M",
"id": "14",
"numberOfStops": 0,
"blacklistedInEU": false
}
]
}
],
"price": {
"currency": "EUR",
"total": "4048.84",
"base": "3858.00",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
}
],
"grandTotal": "4048.84"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": true
},
"validatingAirlineCodes": [
"MU"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "EUR",
"total": "4048.84",
"base": "3858.00"
},
"fareDetailsBySegment": [
{
"segmentId": "13",
"cabin": "ECONOMY",
"fareBasis": "YSE0WDNQ",
"class": "Y",
"includedCheckedBags": {
"quantity": 2
}
},
{
"segmentId": "14",
"cabin": "BUSINESS",
"fareBasis": "QSE0WCNL",
"class": "Q",
"includedCheckedBags": {
"quantity": 2
}
}
]
}
]
}
in order to apply the filter for cabin class, I suggest you to try with POST method.
in POST method has more search criteria you can apply, below example is something that I have tried and it works: response only contains ECONOMY classes by updating values under cabinRestrictions.
details of the request model is available in API reference page
amadeus.shopping.flightOffersSearch.post(JSON.stringify({
"currencyCode": "USD",
"originDestinations": [
{
"id": "1",
"originLocationCode": "SYD",
"destinationLocationCode": "BKK",
"departureDateTimeRange": {
"date": "2022-11-01"
}
}
],
"travelers": [
{
"id": "1",
"travelerType": "ADULT"
}
],
"sources": [
"GDS"
],
"searchCriteria": {
"maxFlightOffers": 10,
"flightFilters": {
"cabinRestrictions": [
{
"cabin": "ECONOMY",
"coverage": "ALL_SEGMENTS",
"originDestinationIds": [
1
]
}
]
}
}
})).then(...)

Elasticsearch to SQL equivalent, get the first and last documents with filter

I have an issue with elasticsearch documents. So the goal is I need to get the latest data close from index stocks and also the last data close from stocks within a specified date. Here's the example of the SQL equivalent:
SELECT (
SELECT `close` FROM `stocks` WHERE date >= 2022-06-01 ORDER by date DESC LIMIT 1
) as last_close,
(
SELECT `close` FROM `stocks` ORDER by date ASC LIMIT 1
) as latest_close FROM stocks
That's the goal I need to achieve, for the rest I think I don't need to share because the bottleneck is on that issue.
Edited: This is the mappings on my index stocks in elasticsearch:
{
"stocks": { -
"mappings": { -
"properties": { -
"avg": { -
"type": "double"
},
"board": { -
"type": "text"
},
"book": { -
"type": "double"
},
"change": { -
"type": "double"
},
"chg": { -
"type": "double"
},
"close": { -
"type": "double"
},
"date": { -
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"der": { -
"type": "double"
},
"eps": { -
"type": "double"
},
"fve": { -
"type": "double"
},
"fvei": { -
"type": "double"
},
"group": { -
"type": "keyword"
},
"high": { -
"type": "double"
},
"low": { -
"type": "double"
},
"open": { -
"type": "double"
},
"paid_up_cap_shares": { -
"type": "text",
"fields": { -
"keyword": { -
"type": "keyword",
"ignore_above": 256
}
}
},
"pbv": { -
"type": "double"
},
"peg_analysis": { -
"type": "text"
},
"peg_ratio": { -
"type": "double"
},
"per": { -
"type": "double"
},
"prev": { -
"type": "double"
},
"roe": { -
"type": "double"
},
"stock": { -
"type": "keyword"
},
"trade_freq": { -
"type": "double"
},
"trade_val": { -
"type": "double"
},
"trade_vol": { -
"type": "double"
}
}
}
}
}
And here's the document example for the index:
{
"_index": "stocks",
"_id": "6odITIEBRQt2Zq4UUGu3",
"_score": 1.0,
"_source": {
"date": "2022-06-10 13:23:36",
"fvei": "112833.74",
"pbv": "0.0",
"prev": "97",
"book": "-1.185716459E8",
"roe": "-7.87",
"der": "-6.87",
"high": "91",
"avg": "91.0",
"fve": "91.0",
"low": "91",
"stock": "WINR",
"per": "0.0",
"close": "91",
"trade_vol": "46283600",
"group": "IDXPROPERT",
"paid_up_cap_shares": "0.1",
"trade_val": "4211807600",
"chg": "-6.59",
"change": "-6.0",
"peg_ratio": "0.0",
"eps": "9327072.3",
"trade_freq": "1433",
"peg_analysis": "negative growth",
"board": "RG",
"open": "91"
}
},
{
"_index": "stocks",
"_id": "7IdITIEBRQt2Zq4UUGu3",
"_score": 1.0,
"_source": {
"date": "2022-06-10 13:23:36",
"fvei": "66215.12",
"pbv": "0.0",
"prev": "685",
"book": "1946574.58",
"roe": "22.08",
"der": "3.62",
"high": "685",
"avg": "677.5",
"fve": "680.0",
"low": "670",
"stock": "TLDN",
"per": "0.0",
"close": "680",
"trade_vol": "577600",
"group": "IDXNONCYC",
"paid_up_cap_shares": "540.65",
"trade_val": "393001500",
"chg": "-0.73",
"change": "-5.0",
"peg_ratio": "0.0",
"eps": "429847.27",
"trade_freq": "117",
"peg_analysis": "negative growth",
"board": "RG",
"open": "685"
}
},
I have found the answer by using top_hits:
{
"query": {
"bool": {
"must": [
{
// range filter
"range": {
"date": {
"gte": "now-89d",
"lte": "now+1d"
}
}
}
]
}
},
"aggs": {
"group": {
"terms": {
"field": "stock"
},
"aggs": {
"last_doc": {
"top_hits": {
"size": 1,
"sort": [
{
"date": {
"order": "desc"
}
}
],
"_source": {
"includes": ["close"]
}
}
},
"first_doc": {
"top_hits": {
"size": 1,
"sort": [
{
"date": {
"order": "asc"
}
}
],
"_source": {
"includes": ["close"]
}
}
}
}
}
}
}

I keep getting 400 error(travelerId not existing) on calling the CreateOrder API

I am on a test Account.
On printing the travelerPricings Object to console, I have this
[
{
travelerId: '1',
fareOption: 'STANDARD',
travelerType: 'ADULT',
price: {
currency: '',
total: '',
base: '',
taxes: [Array],
refundableTaxes: ''
},
fareDetailsBySegment: [ [Object], [Object], [Object], [Object] ]
},
{
travelerId: '2',
fareOption: 'STANDARD',
travelerType: 'CHILD',
price: {
currency: '',
total: '',
base: '',
taxes: [Array],
refundableTaxes: ''
},
fareDetailsBySegment: [ [Object], [Object], [Object], [Object] ]
}
]
Yet on the Api Response, I keep getting the error pointer as
/data/flightOffers[0]/travelerPricings[1]"
Which is not true. As seen in the log shared above,
travelerPricings[1].travelerId = '2'
Please Why could this error come up? Thanks
Based on the Request, Here is the sample payload
{"data":
{
"flightOffers": [
{
"type": "flight-offer",
"id": "1",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"paymentCardRequired": false,
"lastTicketingDate": "2022-08-01",
"itineraries": [
{
"segments": [
{
"departure": {
"iataCode": "SYD",
"terminal": "1",
"at": "2022-08-01T11:35:00"
},
"arrival": {
"iataCode": "MNL",
"terminal": "2",
"at": "2022-08-01T16:50:00"
},
"carrierCode": "PR",
"number": "212",
"aircraft": {
"code": "333"
},
"operating": {
"carrierCode": "PR"
},
"duration": "PT7H15M",
"id": "15",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 716,
"weightUnit": "KG",
"cabin": "BUSINESS"
}
]
},
{
"departure": {
"iataCode": "MNL",
"terminal": "1",
"at": "2022-08-01T19:20:00"
},
"arrival": {
"iataCode": "BKK",
"at": "2022-08-01T21:50:00"
},
"carrierCode": "PR",
"number": "732",
"aircraft": {
"code": "320"
},
"operating": {
"carrierCode": "PR"
},
"duration": "PT3H30M",
"id": "16",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 148,
"weightUnit": "KG",
"cabin": "BUSINESS"
}
]
}
]
},
{
"segments": [
{
"departure": {
"iataCode": "BKK",
"at": "2022-08-05T22:50:00"
},
"arrival": {
"iataCode": "MNL",
"terminal": "2",
"at": "2022-08-06T03:15:00"
},
"carrierCode": "PR",
"number": "733",
"aircraft": {
"code": "321"
},
"operating": {
"carrierCode": "PR"
},
"duration": "PT3H25M",
"id": "59",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 148,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
},
{
"departure": {
"iataCode": "MNL",
"terminal": "1",
"at": "2022-08-06T22:10:00"
},
"arrival": {
"iataCode": "SYD",
"terminal": "1",
"at": "2022-08-07T09:45:00"
},
"carrierCode": "PR",
"number": "211",
"aircraft": {
"code": "333"
},
"operating": {
"carrierCode": "PR"
},
"duration": "PT9H35M",
"id": "60",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 358,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
}
]
}
],
"price": {
"currency": "NGN",
"total": "1479460.00",
"base": "1298255.00",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
},
{
"amount": "0.00",
"type": "FORM_OF_PAYMENT"
}
],
"grandTotal": "1479460.00",
"billingCurrency": "NGN"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": false
},
"validatingAirlineCodes": [
"PR"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "NGN",
"total": "840536",
"base": "740769",
"taxes": [
{
"amount": "384.00",
"code": "G8"
},
{
"amount": "19112.00",
"code": "WY"
},
{
"amount": "896.00",
"code": "E7"
},
{
"amount": "18329.00",
"code": "AU"
},
{
"amount": "42766.00",
"code": "YQ"
},
{
"amount": "9320.00",
"code": "LI"
},
{
"amount": "8960.00",
"code": "TS"
}
],
"refundableTaxes": "108123"
},
"fareDetailsBySegment": [
{
"segmentId": "15",
"cabin": "BUSINESS",
"fareBasis": "DBAU",
"class": "D",
"includedCheckedBags": {
"weight": 40,
"weightUnit": "KG"
}
},
{
"segmentId": "16",
"cabin": "BUSINESS",
"fareBasis": "DBAU",
"class": "D",
"includedCheckedBags": {
"weight": 40,
"weightUnit": "KG"
}
},
{
"segmentId": "59",
"cabin": "ECONOMY",
"fareBasis": "KBAU",
"class": "K",
"includedCheckedBags": {
"weight": 30,
"weightUnit": "KG"
}
},
{
"segmentId": "60",
"cabin": "ECONOMY",
"fareBasis": "KBAU",
"class": "K",
"includedCheckedBags": {
"weight": 30,
"weightUnit": "KG"
}
}
]
},
{
"travelerId": "2",
"fareOption": "STANDARD",
"travelerType": "CHILD",
"price": {
"currency": "NGN",
"total": "638924",
"base": "557486",
"taxes": [
{
"amount": "384.00",
"code": "G8"
},
{
"amount": "19112.00",
"code": "WY"
},
{
"amount": "896.00",
"code": "E7"
},
{
"amount": "42766.00",
"code": "YQ"
},
{
"amount": "9320.00",
"code": "LI"
},
{
"amount": "8960.00",
"code": "TS"
}
],
"refundableTaxes": "89794"
},
"fareDetailsBySegment": [
{
"segmentId": "15",
"cabin": "BUSINESS",
"fareBasis": "DBAU",
"class": "D",
"includedCheckedBags": {
"weight": 40,
"weightUnit": "KG"
}
},
{
"segmentId": "16",
"cabin": "BUSINESS",
"fareBasis": "DBAU",
"class": "D",
"includedCheckedBags": {
"weight": 40,
"weightUnit": "KG"
}
},
{
"segmentId": "59",
"cabin": "ECONOMY",
"fareBasis": "KBAU",
"class": "K",
"includedCheckedBags": {
"weight": 30,
"weightUnit": "KG"
}
},
{
"segmentId": "60",
"cabin": "ECONOMY",
"fareBasis": "KBAU",
"class": "K",
"includedCheckedBags": {
"weight": 30,
"weightUnit": "KG"
}
}
]
}
]
}
],
"travelers": [ {
"id": "1",
"dateOfBirth": "1982-01-16",
"name": {
"firstName": "JORGE",
"lastName": "GONZALES"
},
"gender": "MALE",
"contact": {
"emailAddress": "jorge.gonzales833#telefonica.es",
"phones": [ {
"deviceType": "MOBILE",
"countryCallingCode": "34",
"number": "480080076"
} ]
},
"documents": [ {
"documentType": "PASSPORT",
"birthPlace": "Madrid",
"issuanceLocation": "Madrid",
"issuanceDate": "2015-04-14",
"number": "00000000",
"expiryDate": "2025-04-14",
"issuanceCountry": "ES",
"validityCountry": "ES",
"nationality": "ES",
"holder": true
} ]
} ]
}
MY Request using the NodeSDK
const {data:{flightOffers}} = req.body;
const {result} = await Amadeus.booking.flightOrders.post(
JSON.stringify({
'data': {
'type': 'flight-order',
'flightOffers': [ flightOffers[ 0 ] ],
'travelers': travelers
}
})
);
This is quite lengthy, but I did this so it is easy to just re-create the exact Scenario in case the issue is somewhere in the payload I am sending.
When you request Flight Create Order API, you have only put 1 traveler's information at the end that's why the error comes. you are requesting for flight order for 2 persons (1 adult and 1 child) so both information should be attached at the end.
below is a node example for the entire flow from Flight offer search, pricing, and create order. you may get a different error if some segments are not available, but the issue that you faced regarding travelers is resolved.
amadeus.shopping.flightOffersSearch.get({
originLocationCode: 'SYD',
destinationLocationCode: 'BKK',
departureDate: '2022-08-01',
adults: '1',
children: '1'
}).then(function (flightOffersResponse) {
return amadeus.shopping.flightOffers.pricing.post(
JSON.stringify({
'data': {
'type': 'flight-offers-pricing',
'flightOffers': [flightOffersResponse.data[0]]
}
})
)
}).then(function (pricingResponse) {
return amadeus.booking.flightOrders.post(
JSON.stringify({
'data': {
'type': 'flight-order',
'flightOffers': [pricingResponse.data.flightOffers[0]],
'travelers': [{
"id": "1",
"dateOfBirth": "1982-01-16",
"name": {
"firstName": "JORGE",
"lastName": "GONZALES"
},
"gender": "MALE",
"contact": {
"emailAddress": "jorge.gonzales833#telefonica.es",
"phones": [{
"deviceType": "MOBILE",
"countryCallingCode": "34",
"number": "480080076"
}]
},
"documents": [{
"documentType": "PASSPORT",
"birthPlace": "Madrid",
"issuanceLocation": "Madrid",
"issuanceDate": "2015-04-14",
"number": "00000000",
"expiryDate": "2025-04-14",
"issuanceCountry": "ES",
"validityCountry": "ES",
"nationality": "ES",
"holder": true
}]
},
{
"id": "2",
"dateOfBirth": "2012-10-11",
"gender": "FEMALE",
"contact": {
"emailAddress": "jorge.gonzales833#telefonica.es",
"phones": [
{
"deviceType": "MOBILE",
"countryCallingCode": "34",
"number": "480080076"
}
]
},
"name": {
"firstName": "ADRIANA",
"lastName": "GONZALES"
}
}]
}
})
);
}).then(function (response) {
console.log(response);
}).catch(function (response) {
console.error(response);
});