I am working on building a flight price search website as part of a project and have managed to get most of the functionality I require working.
Here's what the front-end looks like so far:
When users enter in the details, a POST request is sent to an API.
API: https://developers.amadeus.com/self-service/category/air/api-doc/flight-offers-search
API Python SDK: https://github.com/amadeus4dev/amadeus-python
I'm receiving a response from the API; however, am struggling to understand what I should then do with the information received. The next step is to pass the information from the API into a search results template and split out all of the received flight information, similar to how it is displayed on Sky Scanner:
Below is what I have in my views.py so far (currently passing in the whole response, in what I believe is JSON format?)
Views.py:
def flight_search(request):
kwargs = {'originLocationCode': request.POST.get('Origincity'),
'destinationLocationCode': request.POST.get('Destinationcity'),
'departureDate': request.POST.get('Departuredate'),
'returnDate': request.POST.get('Returndate'),
'adults': '1'}
try:
response = amadeus.shopping.flight_offers_search.get(
**kwargs)
print(response.data)
return render(request, "flightfinder/flight_search.html", {
"response": response
})
except ResponseError as error:
raise error
Here is an example response from the API:
{
"meta": {
"count": 2
},
"data": [
{
"type": "flight-offer",
"id": "1",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"oneWay": false,
"lastTicketingDate": "2020-11-20",
"numberOfBookableSeats": 2,
"itineraries": [
{
"duration": "PT22H40M",
"segments": [
{
"departure": {
"iataCode": "GIG",
"terminal": "2",
"at": "2020-12-01T16:30:00"
},
"arrival": {
"iataCode": "CDG",
"terminal": "2E",
"at": "2020-12-02T07:45:00"
},
"carrierCode": "AF",
"number": "443",
"aircraft": {
"code": "77W"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT11H15M",
"id": "3",
"numberOfStops": 0,
"blacklistedInEU": false
},
{
"departure": {
"iataCode": "ORY",
"terminal": "2",
"at": "2020-12-02T17:10:00"
},
"arrival": {
"iataCode": "MAD",
"terminal": "2",
"at": "2020-12-02T19:10:00"
},
"carrierCode": "AF",
"number": "4792",
"aircraft": {
"code": "73H"
},
"operating": {
"carrierCode": "UX"
},
"duration": "PT2H",
"id": "4",
"numberOfStops": 0,
"blacklistedInEU": false
}
]
},
{
"duration": "PT15H5M",
"segments": [
{
"departure": {
"iataCode": "MAD",
"terminal": "2",
"at": "2020-12-12T20:05:00"
},
"arrival": {
"iataCode": "CDG",
"terminal": "2F",
"at": "2020-12-12T22:20:00"
},
"carrierCode": "AF",
"number": "1101",
"aircraft": {
"code": "319"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT2H15M",
"id": "5",
"numberOfStops": 0,
"blacklistedInEU": false
},
{
"departure": {
"iataCode": "CDG",
"terminal": "2E",
"at": "2020-12-12T23:35:00"
},
"arrival": {
"iataCode": "GIG",
"terminal": "2",
"at": "2020-12-13T07:10:00"
},
"carrierCode": "AF",
"number": "442",
"aircraft": {
"code": "77W"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT11H35M",
"id": "6",
"numberOfStops": 0,
"blacklistedInEU": false
}
]
}
],
"price": {
"currency": "USD",
"total": "2324.04",
"base": "2089.00",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
}
],
"grandTotal": "2324.04"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": false
},
"validatingAirlineCodes": [
"AF"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "USD",
"total": "1311.52",
"base": "1194.00"
},
"fareDetailsBySegment": [
{
"segmentId": "3",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "O",
"includedCheckedBags": {
"quantity": 2
}
},
{
"segmentId": "4",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "J",
"includedCheckedBags": {
"quantity": 2
}
},
{
"segmentId": "5",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "L",
"includedCheckedBags": {
"quantity": 0
}
},
{
"segmentId": "6",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "R",
"includedCheckedBags": {
"quantity": 0
}
}
]
},
{
"travelerId": "2",
"fareOption": "STANDARD",
"travelerType": "CHILD",
"price": {
"currency": "USD",
"total": "1012.52",
"base": "895.00"
},
"fareDetailsBySegment": [
{
"segmentId": "3",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "O"
},
{
"segmentId": "4",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "J"
},
{
"segmentId": "5",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "L"
},
{
"segmentId": "6",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "R"
}
]
}
]
},
{
"type": "flight-offer",
"id": "2",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"oneWay": false,
"lastTicketingDate": "2020-11-20",
"numberOfBookableSeats": 2,
"itineraries": [
{
"duration": "PT15H10M",
"segments": [
{
"departure": {
"iataCode": "GIG",
"terminal": "2",
"at": "2020-12-01T16:30:00"
},
"arrival": {
"iataCode": "CDG",
"terminal": "2E",
"at": "2020-12-02T07:45:00"
},
"carrierCode": "AF",
"number": "443",
"aircraft": {
"code": "77W"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT11H15M",
"id": "1",
"numberOfStops": 0,
"blacklistedInEU": false
},
{
"departure": {
"iataCode": "CDG",
"terminal": "2F",
"at": "2020-12-02T09:35:00"
},
"arrival": {
"iataCode": "MAD",
"terminal": "2",
"at": "2020-12-02T11:40:00"
},
"carrierCode": "AF",
"number": "1300",
"aircraft": {
"code": "319"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT2H5M",
"id": "2",
"numberOfStops": 0,
"blacklistedInEU": false
}
]
},
{
"duration": "PT15H5M",
"segments": [
{
"departure": {
"iataCode": "MAD",
"terminal": "2",
"at": "2020-12-12T20:05:00"
},
"arrival": {
"iataCode": "CDG",
"terminal": "2F",
"at": "2020-12-12T22:20:00"
},
"carrierCode": "AF",
"number": "1101",
"aircraft": {
"code": "319"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT2H15M",
"id": "5",
"numberOfStops": 0,
"blacklistedInEU": false
},
{
"departure": {
"iataCode": "CDG",
"terminal": "2E",
"at": "2020-12-12T23:35:00"
},
"arrival": {
"iataCode": "GIG",
"terminal": "2",
"at": "2020-12-13T07:10:00"
},
"carrierCode": "AF",
"number": "442",
"aircraft": {
"code": "77W"
},
"operating": {
"carrierCode": "AF"
},
"duration": "PT11H35M",
"id": "6",
"numberOfStops": 0,
"blacklistedInEU": false
}
]
}
],
"price": {
"currency": "USD",
"total": "2334.44",
"base": "2089.00",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
}
],
"grandTotal": "2334.44"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": false
},
"validatingAirlineCodes": [
"AF"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "USD",
"total": "1316.72",
"base": "1194.00"
},
"fareDetailsBySegment": [
{
"segmentId": "1",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "O",
"includedCheckedBags": {
"quantity": 2
}
},
{
"segmentId": "2",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "J",
"includedCheckedBags": {
"quantity": 2
}
},
{
"segmentId": "5",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "L",
"includedCheckedBags": {
"quantity": 0
}
},
{
"segmentId": "6",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "R",
"includedCheckedBags": {
"quantity": 0
}
}
]
},
{
"travelerId": "2",
"fareOption": "STANDARD",
"travelerType": "CHILD",
"price": {
"currency": "USD",
"total": "1017.72",
"base": "895.00"
},
"fareDetailsBySegment": [
{
"segmentId": "1",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "O"
},
{
"segmentId": "2",
"cabin": "BUSINESS",
"fareBasis": "OS52OOND",
"brandedFare": "BUSINESS",
"class": "J"
},
{
"segmentId": "5",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "L"
},
{
"segmentId": "6",
"cabin": "ECONOMY",
"fareBasis": "RL50TCLD",
"brandedFare": "LIGHT3",
"class": "R"
}
]
}
]
}
],
"dictionaries": {
"locations": {
"MAD": {
"cityCode": "MAD",
"countryCode": "ES"
},
"GIG": {
"cityCode": "RIO",
"countryCode": "BR"
},
"CDG": {
"cityCode": "PAR",
"countryCode": "FR"
},
"ORY": {
"cityCode": "PAR",
"countryCode": "FR"
}
},
"aircraft": {
"77W": "BOEING 777-300ER",
"319": "AIRBUS A319",
"73H": "BOEING 737-800 (WINGLETS)"
},
"currencies": {
"USD": "US DOLLAR"
},
"carriers": {
"UX": "AIR EUROPA",
"AF": "AIR FRANCE"
}
}
}
My question is: how should I pass this information to the search results template so that I can populate the page with all of the flight information?
Should I pull out the information I need into lists and then pass these through to the template which displays the flight search results? (I'm not sure how I would then ensure the information pertained to a particular flight on the search results template)
Or should I simply pass the response and then extract the information from it on the template?
My apologies for the vague question here, please let me know if you require any additional information - I'm essentially stuck on how to handle this response and would really appreciate any guidance that anybody has.
Thank you!
Related
I have a text field ['Region'] with four values {Global, AMER, APAC, EMEA}. I have a simple bar chart and want the label to be bold only for 'Global' but have been unable to do so.
I tried:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": { "values": [
{"Region": "Global", "Months": 1, "RegionRank":1},
{"Region": "AMER", "Months": -1, "RegionRank":2},
{"Region": "APAC", "Months": 3, "RegionRank":3}, {"Region": "EMEA", "Months": 2, "RegionRank":4}
]},
"layer": [
{
"mark": {
"type": "bar",
"filled": false,
"stroke": "gray",
"strokeDash": [3.6],
"strokeWidth": 3
}
},
{
"mark": {
"type": "text",
"fontSize": 14,
"xOffset": {
"expr": "datum['Months']<0 ? -15:15"
}
},
"encoding": {
"text": {
"field": "Months",
"format": "+.0f"
}
}
}
],
"encoding": {
"y": {
"field": "Region",
"type": "nominal",
"axis": {
"offset": 10,
"title": null,
// problem section
"labelFontWeight": {
"condition": {"test": "datum['Region'] == 'Global'","value":"bold"},
"value":"normal"
}
},
"sort": {
"op": "min",
"field": "RegionRank",
"order": "ascending"
}
},
"x": {
"field": "Months",
"type": "quantitative",
"axis": {"title": null}
}
}
}
but there is no change to the label font weight.
What is interesting is that I switched the result conditions, making the '==Global' result "normal" and the else "bold" and it changed font weight on all the labels to bold. That leads me to believe that my condition is never being evaluated as true. Any ideas why? Is what I want to do - changing a signal value in an axis label - possible?
You mean like this?
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"Region": "Global", "Months": 1, "RegionRank": 1},
{"Region": "AMER", "Months": -1, "RegionRank": 2},
{"Region": "APAC", "Months": 3, "RegionRank": 3},
{"Region": "EMEA", "Months": 2, "RegionRank": 4}
]
},
"layer": [
{
"mark": {
"type": "bar",
"filled": false,
"stroke": "gray",
"strokeDash": [3.6],
"strokeWidth": 3
}
},
{
"mark": {
"type": "text",
"fontSize": 14,
"xOffset": {"expr": "datum['Months']<0 ? -15:15"}
},
"encoding": {"text": {"field": "Months", "format": "+.0f"}}
}
],
"encoding": {
"y": {
"field": "Region",
"type": "nominal",
"axis": {
"offset": 10,
"title": null,
"labelFontWeight": {
"condition": {"test": "datum.label == 'Global'", "value": "bold"},
"value": "normal"
}
},
"sort": {"op": "min", "field": "RegionRank", "order": "ascending"}
},
"x": {"field": "Months", "type": "quantitative", "axis": {"title": null}}
}
}
I have the chart on the left, code provided below, and would like to get the chart on the right. The chart on the right has the bars highlighted that correspond to a selected tier; the tier selected comes from a slicer. (The right chart shows Tier 1; however, the user may prefer a different tier.) I feel like this can be accomplished using fillOpacity. How do I get the highlighting?
{
"data": {
"values": [
{"name": "A", "group": "High", "tier": "Tier 3"},
{"name": "B", "group": "Med", "tier": "Tier 1"},
{"name": "C", "group": "High", "tier": "Tier 1"},
{"name": "D", "group": "High", "tier": "Tier 2"},
{"name": "E", "group": "Low", "tier": "Tier 3"},
{"name": "F", "group": "Low", "tier": "Tier 1"}
]
},
"transform": [
{
"aggregate": [
{
"field": "name",
"op": "count",
"as": "numProj"
}
],
"groupby": [
"name",
"group"
]
},
{
"stack": "numProj",
"groupby": ["group"],
"sort": [
{
"field": "name",
"order": "descending"
}
],
"as": "barTop"
}
],
"layer": [
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true
},
"encoding": {
"y": {
"field": "numProj",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"dy": -10
},
"encoding": {
"y": {
"field": "barTop",
"type": "quantitative"
},
"text": {
"field": "name"
}
}
}
],
"encoding": {
"x": {
"field": "group",
"type": "nominal",
"axis": {
"title": null,
"labelAngle": 0
}
}
}
}
Highlighting in Deneb is quite involved and can be read about here. Having said that, I have a working example.
Code
{
"data": {"name": "dataset"},
"layer": [
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true,
"opacity": 0.3
},
"encoding": {
"y": {
"field": "test",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true,
"opacity": 1
},
"encoding": {
"y": {
"field": "test__highlight",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"dy": 70
},
"encoding": {
"y": {
"field": "test__highlight",
"stack": true,
"type": "quantitative"
},
"text": {
"field": "name"
}
}
}
],
"encoding": {
"x": {
"field": "group",
"type": "nominal",
"axis": {
"title": null,
"labelAngle": 0
}
}
}
}
Things to keep in mind.
You need a measure (Deneb docs state highlighting doesn't work without a measure). The measure named test is simply test = COUNT('Table'[name])
You can't highlight from a slicer unless it is disconnected as slicers filter instead of highlight
You can't highlight stacks in position. The highlighted stacks naturally fall to the bottom as a result of how the data is being passed. There may be a way around this but it will involve further investigation which is probably not worth it.
Edit 1
Highlighting in place.
{
"data": {"name": "dataset"},
"layer": [
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true,
"opacity": 0.3
},
"encoding": {
"y": {
"field": "test",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true
},
"encoding": {
"y": {
"field": "test",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"opacity": {
"condition": {
"test": "datum['test__highlight']!=null"
,
"value": 1
},
"value": 0
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"dy": 70
},
"encoding": {
"y": {
"field": "test",
"stack": true,
"type": "quantitative"
},
"text": {
"field": "name"
}
}
}
],
"encoding": {
"x": {
"field": "group",
"type": "nominal",
"axis": {
"title": null,
"labelAngle": 0
}
}
}
}
We're trying to geocode a location in Poland, using a street, zip code and a city name, but seem to get wrong result. We're looking for: DĄBROWSKIEGO , 82-300 ELBLĄG
Request:
https://geocoder.ls.hereapi.com/6.2/geocode.json?apiKey={API_KEY}&searchtext=D%C4%84BROWSKIEGO%2B,%2B82-300%2BELBL%C4%84G
Instead of a road of that name in the city of Elbląg we get a street of the same name in Poznań:
{
"Response": {
"MetaInfo": {
"Timestamp": "2021-05-11T10:40:48.113+0000"
},
"View": [
{
"Result": [
{
"Relevance": 0.65,
"MatchLevel": "houseNumber",
"MatchQuality": {
"Street": [
0.5
],
"HouseNumber": 1.0
},
"MatchType": "pointAddress",
"Location": {
"LocationId": "here:af:streetsection:nKjv5QtDTbhcQ-QErVaJvA:CgcIBCDCwO9pEAEaAzMwMA",
"LocationType": "point",
"DisplayPosition": {
"Latitude": 52.42663,
"Longitude": 16.85675
},
"NavigationPosition": [
{
"Latitude": 52.42678,
"Longitude": 16.85687
}
],
"MapView": {
"TopLeft": {
"Latitude": 52.42753,
"Longitude": 16.85528
},
"BottomRight": {
"Latitude": 52.42573,
"Longitude": 16.85822
}
},
"Address": {
"Label": "ulica gen. Jana H. Dąbrowskiego 300, 60-406 Poznań, Polska",
"Country": "POL",
"State": "Woj. Wielkopolskie",
"County": "Poznań",
"City": "Poznań",
"District": "Poznań",
"Subdistrict": "Jeżyce",
"Street": "ulica gen. Jana H. Dąbrowskiego",
"HouseNumber": "300",
"PostalCode": "60-406",
"AdditionalData": [
{
"value": "Polska",
"key": "CountryName"
},
{
"value": "Woj. Wielkopolskie",
"key": "StateName"
},
{
"value": "Poznań",
"key": "CountyName"
}
]
}
}
}
],
"ViewId": 0
}
]
}
}
Trying to use newer api gives the same results:
https://geocode.search.hereapi.com/v1/geocode?apiKey={API_KEY}&q=D%C4%84BROWSKIEGO%2B,%2B82-300%2BELBL%C4%84G
{
"items": [
{
"title": "ulica gen. Jana H. Dąbrowskiego 300, 60-406 Poznań, Polska",
"id": "here:af:streetsection:nKjv5QtDTbhcQ-QErVaJvA:CgcIBCDCwO9pEAEaAzMwMA",
"resultType": "houseNumber",
"houseNumberType": "PA",
"address": {
"label": "ulica gen. Jana H. Dąbrowskiego 300, 60-406 Poznań, Polska",
"countryCode": "POL",
"countryName": "Polska",
"state": "Woj. Wielkopolskie",
"county": "Poznań",
"city": "Poznań",
"district": "Poznań",
"subdistrict": "Jeżyce",
"street": "ulica gen. Jana H. Dąbrowskiego",
"postalCode": "60-406",
"houseNumber": "300"
},
"position": {
"lat": 52.42663,
"lng": 16.85675
},
"access": [
{
"lat": 52.42678,
"lng": 16.85687
}
],
"mapView": {
"west": 16.85528,
"south": 52.42573,
"east": 16.85822,
"north": 52.42753
},
"scoring": {
"queryScore": 0.65,
"fieldScore": {
"streets": [
0.5
],
"houseNumber": 1.0
}
}
}
]
}
Looking for a different street in the city of Elbląg gives us proper result:
Łęczycka, 82-300 ELBLĄG
https://geocoder.ls.hereapi.com/6.2/geocode.json?apiKey={API_KEY}&searchtext=%C5%81%C4%99czycka%2B,%2B82-300%2BELBL%C4%84G
{
"Response": {
"MetaInfo": {
"Timestamp": "2021-05-11T10:43:15.578+0000"
},
"View": [
{
"Result": [
{
"Relevance": 0.99,
"MatchLevel": "street",
"MatchQuality": {
"City": 1.0,
"Street": [
0.9
],
"PostalCode": 1.0
},
"Location": {
"LocationId": "here:af:street:SHP1-8Tzm6jtHKMvaFxTLA",
"LocationType": "point",
"DisplayPosition": {
"Latitude": 54.16571,
"Longitude": 19.46824
},
"NavigationPosition": [
{
"Latitude": 54.16571,
"Longitude": 19.46824
}
],
"MapView": {
"TopLeft": {
"Latitude": 54.17117,
"Longitude": 19.43421
},
"BottomRight": {
"Latitude": 54.15544,
"Longitude": 19.50485
}
},
"Address": {
"Label": "ulica Łęczycka, 82-300 Elbląg, Polska",
"Country": "POL",
"State": "Woj. Warmińsko-Mazurskie",
"County": "Elbląg",
"City": "Elbląg",
"District": "Elbląg",
"Street": "ulica Łęczycka",
"PostalCode": "82-300",
"AdditionalData": [
{
"value": "Polska",
"key": "CountryName"
},
{
"value": "Woj. Warmińsko-Mazurskie",
"key": "StateName"
},
{
"value": "Elbląg",
"key": "CountyName"
}
]
}
}
}
],
"ViewId": 0
}
]
}
}
Is there anything we're doing wrong when invoking the requests?
Now it returns correct results:
https://geocoder.ls.hereapi.com/6.2/geocode.json?language=en-US&maxresults=20&searchtext=D%C4%84BROWSKIEGO+82-300+ELBL%C4%84G&apikey=***
Result:
{
"Response": {
"MetaInfo": {
"Timestamp": "2021-07-20T12:23:56.560+0000"
},
"View": [
{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [
{
"Relevance": 1,
"MatchLevel": "street",
"MatchQuality": {
"City": 1,
"Street": [
0.57
],
"PostalCode": 1
},
"Location": {
"LocationId": "NT_mqHTX7fWyBVgpiaYyp.VAB",
"LocationType": "point",
"DisplayPosition": {
"Latitude": 54.15047,
"Longitude": 19.45583
},
"NavigationPosition": [
{
"Latitude": 54.15047,
"Longitude": 19.45583
}
],
"MapView": {
"TopLeft": {
"Latitude": 54.15449,
"Longitude": 19.44247
},
"BottomRight": {
"Latitude": 54.15029,
"Longitude": 19.46051
}
},
"Address": {
"Label": "ulica gen. Jarosława Dąbrowskiego, 82-300 Elbląg, Poland",
"Country": "POL",
"State": "Woj. Warmińsko-Mazurskie",
"County": "Elbląg",
"City": "Elbląg",
"District": "Elbląg",
"Street": "ulica gen. Jarosława Dąbrowskiego",
"PostalCode": "82-300",
"AdditionalData": [
{
"value": "Poland",
"key": "CountryName"
},
{
"value": "Woj. Warmińsko-Mazurskie",
"key": "StateName"
},
{
"value": "Elbląg",
"key": "CountyName"
}
]
}
}
}
]
}
]
}
}
This GS7 request
https://search.hereapi.com/v1/geocode?q=D%C4%84BROWSKIEGO+82-300+ELBL%C4%84G&at=51.9206796%2C17.2954345&lang=en-US&limit=20&apikey=***
returns incorrect result - but will be fixed soon.
Is it possible to make partial refund using Authorize.Net? E.g. I have a transaction by 300$. First time I need to make a refund 100$ on this transaction. And second time to make a refund 50$.
What kind of transaction status will be after that?
first request:
...
"refId": "123456",
"transactionRequest": {
"transactionType": "refundTransaction",
"amount": "100.00",}
"refTransId": "1234567890"
}
...
second request:
...
"refId": "123456",
"transactionRequest": {
"transactionType": "refundTransaction",
"amount": "50.00",}
"refTransId": "1234567890"
}
...
Yes, you can make multiple refunds against one transaction as long as you do not go over the original transaction amount.
Below I made a $50 payment and then following up with a $20 and $10 refund. Both were successful.
Here is my original AUTH_CAPTURE request:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "",
"transactionKey": ""
},
"refId": 38947161,
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": 100,
"payment": {
"creditCard": {
"cardNumber": "4111111111111111",
"expirationDate": "122020",
"cardCode": "999"
}
},
"order": {
"invoiceNumber": "1324567890",
"description": "this is a test transaction"
},
"lineItems": {
"lineItem": [
{
"itemId": "1",
"name": "vase",
"description": "Cannes logo",
"quantity": "18",
"unitPrice": "45.00"
},
{
"itemId": "2",
"name": "desk",
"description": "Big Desk",
"quantity": "10",
"unitPrice": "85.00"
}
]
},
"tax": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"duty": {
"amount": "8.55",
"name": "duty name",
"description": "duty description"
},
"shipping": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"poNumber": "456654",
"customer": {
"id": "18",
"email": "someone#blackhole.tv"
},
"billTo": {
"firstName": "Ellen",
"lastName": "Johnson",
"company": "Souveniropolis",
"address": "14 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"shipTo": {
"firstName": "China",
"lastName": "Bayles",
"company": "Thyme for Tea",
"address": "12 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"customerIP": "192.168.1.1",
"transactionSettings": {
"setting": [
{
"settingName": "allowPartialAuth",
"settingValue": "false"
},
{
"settingName": "duplicateWindow",
"settingValue": "0"
},
{
"settingName": "emailCustomer",
"settingValue": "false"
},
{
"settingName": "recurringBilling",
"settingValue": "false"
},
{
"settingName": "testRequest",
"settingValue": "false"
}
]
},
"userFields": {
"userField": {
"name": "favorite_color",
"value": "blue"
}
}
}
}
}
Here is my original AUTH_CAPTURE response:
{
"transactionResponse": {
"responseCode": "1",
"authCode": "TTJ26B",
"avsResultCode": "Y",
"cvvResultCode": "P",
"cavvResultCode": "2",
"transId": "40032153203",
"refTransID": "",
"transHash": "",
"testRequest": "0",
"accountNumber": "XXXX1111",
"accountType": "Visa",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"userFields": [
{
"name": "favorite_color",
"value": "blue"
}
],
"transHashSha2": "0C9E5A47F93CD5B770A6B4AB24FE0F0D6F3B909066C72A10C4746F48C9886527A18B654736AE8D920D9048A14F2823A0DEC5B5F775A1C48DE9CBCF41C8D28CA3",
"SupplementalDataQualificationIndicator": 0
},
"refId": "38947161",
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
Here is my first REFUND request (successful):
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "",
"transactionKey": ""
},
"refId": 30777668,
"transactionRequest": {
"transactionType": "refundTransaction",
"amount": 20,
"payment": {
"creditCard": {
"cardNumber": "4111111111111111",
"expirationDate": "122020"
}
},
"authCode": "40032153203"
}
}
}
Here is my first REFUND response (successful):
{
"transactionResponse": {
"responseCode": "1",
"authCode": "",
"avsResultCode": "P",
"cvvResultCode": "",
"cavvResultCode": "",
"transId": "40032153314",
"refTransID": "",
"transHash": "",
"testRequest": "0",
"accountNumber": "XXXX1111",
"accountType": "Visa",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"transHashSha2": "4CE2D83B56C09494AD5609440E3337A6DEE0F4C74FBC99B218D65F6A121EFFC269F8954AC47C17B3B739E61A860C7B0818A8497D85D314D6E0CD89C9FE71A071",
"SupplementalDataQualificationIndicator": 0
},
"refId": "30777668",
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
Here is my second REFUND request (successful):
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "",
"transactionKey": ""
},
"refId": 40597686,
"transactionRequest": {
"transactionType": "refundTransaction",
"amount": 10,
"payment": {
"creditCard": {
"cardNumber": "4111111111111111",
"expirationDate": "122020"
}
},
"authCode": "40032153203"
}
}
}
Here is my second REFUND response (successful):
{
"transactionResponse": {
"responseCode": "1",
"authCode": "",
"avsResultCode": "P",
"cvvResultCode": "",
"cavvResultCode": "",
"transId": "40032153319",
"refTransID": "",
"transHash": "",
"testRequest": "0",
"accountNumber": "XXXX1111",
"accountType": "Visa",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"transHashSha2": "FD146FC0F8F3F31068905EC6C8D252662AA735ACDFAC53B4A8D808060C244C06288700AA8872466C3E240B62130D010CFBDE0473D09B631514A6E2E2CB77804F",
"SupplementalDataQualificationIndicator": 0
},
"refId": "40597686",
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
I am working on Facebook analytic, Here is a query which is supposed to fetch the summary of the reactions from Facebook page posts,
Note: posts json is as it is inserted to elastic-search db
{
"query": {
"match": {
"from.id": "[Page-id]"
}
},
"aggs": {
"summary_reaction": {
"terms": {
"field": "reactions.data.type.keyword"
}
}
}
}
Only issue is query return unique count whereas it should consider all reactions.
My result is
"aggregations": {
"reaction_summary": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "LIKE",
"doc_count": 2
},
{
"key": "HAHA",
"doc_count": 1
}
]
}
}
here is the sample json
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 6.158189,
"hits": [
{
"_index": "facebook_page",
"_type": "post",
"_id": "AV1RMRKSSM3OTvGpqzx7",
"_score": 6.158189,
"_source": {
"reactions": {
"paging": {
"cursors": {
"after": "TVRFMk9EYzVOekl5TWpjMU5USTJPakUxTURBek1EVTNOREU2TWpVME1EazJNVFl4TXc9PQZDZD",
"before": "TVRFMk9EYzVOekl5TWpjMU5USTJPakUxTURBek1EVTNOREU2TWpVME1EazJNVFl4TXc9PQZDZD"
}
},
"data": [
{
"pic_large": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"type": "LIKE",
"id": "116879722275526",
"name": "Moojaa"
}
]
},
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p50x50/20108099_116879808942184_8792637908147052517_n.png?oh=24cc256b24e5da70f306afcf784a636d&oe=59FBA1D4&__gda__=1509895651_44acee6189c7c1cb6eed023a6e742d1a",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"coordinates": {},
"created_time": "2017-07-17T15:35:35+0000",
"message": "Kuthey e Moojaa",
"type": "status",
"id": "116879722275526_116886608941504"
}
},
{
"_index": "facebook_page",
"_type": "post",
"_id": "AV1RMRViSM3OTvGpqzx8",
"_score": 6.158189,
"_source": {
"reactions": {
"paging": {
"cursors": {
"after": "TVRFMk9EYzVOekl5TWpjMU5USTJPakUxTURBek1EUTBNRGc2TWpVME1EazJNVFl4TXc9PQZDZD",
"before": "TVRBd01ERTFOREl5TkRrNE56Y3dPakUxTURBek1EUTFNams2TWpVME1EazJNVFl4TXc9PQZDZD"
}
},
"data": [
{
"pic_large": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"type": "LIKE",
"id": "111467022710714",
"name": "Ram Singh Shankar"
},
{
"pic_large": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"type": "LIKE",
"id": "116879722275526",
"name": "Moojaa"
}
]
},
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p50x50/20108099_116879808942184_8792637908147052517_n.png?oh=24cc256b24e5da70f306afcf784a636d&oe=59FBA1D4&__gda__=1509895651_44acee6189c7c1cb6eed023a6e742d1a",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"coordinates": {},
"comments": {
"paging": {
"cursors": {
"after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEUyT0RneE5UUTRPVFF5TURFd09qRTFNREF6TURRMk5Eaz0ZD",
"before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEUyT0RneE5EUXlNamMxTXpVME9qRTFNREF6TURRMk1URT0ZD"
}
},
"data": [
{
"message": "test",
"from": {
"picture": {
"data": {
"url": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"is_silhouette": false
}
},
"name": "Ram Singh Shankar",
"id": "111467022710714"
},
"id": "116880885608743_116881442275354"
},
{
"message": "test 2",
"from": {
"picture": {
"data": {
"url": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"is_silhouette": false
}
},
"name": "Ram Singh Shankar",
"id": "111467022710714"
},
"id": "116880885608743_116881548942010"
}
]
},
"created_time": "2017-07-17T15:13:23+0000",
"message": "another Mooja",
"type": "status",
"id": "116879722275526_116880885608743"
}
},
{
"_index": "facebook_page",
"_type": "post",
"_id": "AV1RMRgtSM3OTvGpqzx9",
"_score": 6.158189,
"_source": {
"reactions": {
"paging": {
"cursors": {
"after": "TVRBd01ERTFOREl5TkRrNE56Y3dPakUxTURBek1EUXpPRGM2TnpnNE5qUTRNRE0zT1RFek16RXkZD",
"before": "TVRFMk9EYzVOekl5TWpjMU5USTJPakUxTURBek1EUTVOVEk2TnpnNE5qUTRNRE0zT1RFek16RXkZD"
}
},
"data": [
{
"pic_large": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"type": "HAHA",
"id": "116879722275526",
"name": "Moojaa"
},
{
"pic_large": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"type": "HAHA",
"id": "111467022710714",
"name": "Ram Singh Shankar"
}
]
},
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p50x50/20108099_116879808942184_8792637908147052517_n.png?oh=24cc256b24e5da70f306afcf784a636d&oe=59FBA1D4&__gda__=1509895651_44acee6189c7c1cb6eed023a6e742d1a",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"coordinates": {},
"comments": {
"paging": {
"cursors": {
"after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEUyT0RneE9ESTFOakE0TmpRNU9qRTFNREF6TURRM05EYz0ZD",
"before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEUyT0RneE5UVTRPVFF5TURBNU9qRTFNREF6TURRMk5UUT0ZD"
}
},
"data": [
{
"message": "test 3",
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"id": "116880192275479_116881558942009"
},
{
"message": "test ram",
"from": {
"picture": {
"data": {
"url": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"is_silhouette": false
}
},
"name": "Ram Singh Shankar",
"id": "111467022710714"
},
"id": "116880192275479_116881578942007"
},
{
"message": "test singh",
"from": {
"picture": {
"data": {
"url": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"is_silhouette": false
}
},
"name": "Ram Singh Shankar",
"id": "111467022710714"
},
"id": "116880192275479_116881598942005"
},
{
"message": "khair",
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"id": "116880192275479_116881825608649"
}
]
},
"created_time": "2017-07-17T15:10:12+0000",
"message": "Testing my Mooja",
"type": "status",
"id": "116879722275526_116880192275479"
}
}
]
}
}
You have to set data inside the reactions as nested type and you can do nested aggregation on the data to get all the counts for the type.
Mappings
PUT facebook_index1
{
"mappings": {
"document_type" : {
"properties": {
"reactions" : {
"type": "object",
"properties": {
"data" : {
"type" : "nested",
"properties" : {
"type" : {
"type" : "keyword"
}
}
}
}
}
}
}
}
}
Query
use nested aggs to aggregate for type for data.
POST facebook_index1/_search
{
"size": 0,
"aggs": {
"nested_data_aggs": {
"nested": {
"path": "reactions.data"
},
"aggs": {
"summary_reaction": {
"terms": {
"field": "reactions.data.type",
"size": 10
}
}
}
}
}
}
Hope this works