I am trying to extract data values from a rather large JSON file via php. The file comes from a USGS server and includes a large series of information that I don't need I am just trying to get the data values and not all of the metadata. I have never had to handle JSON files of this magnitude as I am rather new to their format.
{
"name": "ns1:timeSeriesResponseType",
"declaredType": "org.cuahsi.waterml.TimeSeriesResponseType",
"scope": "javax.xml.bind.JAXBElement$GlobalScope",
"value": {
"queryInfo": {
"queryURL": "http://waterservices.usgs.gov/nwis/iv/format=json&sites=01129500&startDT=2017-11-05T18:00-0500&endDT=2017-11-06T03:00-0500¶meterCd=00060&siteStatus=all",
"criteria": {
"locationParam": "[ALL:01129500]",
"variableParam": "[00060]",
"timeParam": {
"beginDateTime": "2017-11-05T23:00:00.000",
"endDateTime": "2017-11-06T08:00:00.000"
},
"parameter": []
},
"note": [
{
"value": "[ALL:01129500]",
"title": "filter:sites"
},
{
"value": "[mode=RANGE, modifiedSince=null] interval={INTERVAL[2017-11-05T23:00:00.000Z/2017-11-06T08:00:00.000Z]}",
"title": "filter:timeRange"
},
{
"value": "methodIds=[ALL]",
"title": "filter:methodId"
},
{
"value": "2017-11-06T21:03:28.078Z",
"title": "requestDT"
},
{
"value": "efbacfd0-c335-11e7-9d73-6cae8b663fb6",
"title": "requestId"
},
{
"value": "Provisional data are subject to revision. Go to http://waterdata.usgs.gov/nwis/help/?provisional for more information.",
"title": "disclaimer"
},
{
"value": "vaas01",
"title": "server"
}
]
},
"timeSeries": [
{
"sourceInfo": {
"siteName": "CONNECTICUT RIVER AT NORTH STRATFORD, NH",
"siteCode": [
{
"value": "01129500",
"network": "NWIS",
"agencyCode": "USGS"
}
],
"timeZoneInfo": {
"defaultTimeZone": {
"zoneOffset": "-05:00",
"zoneAbbreviation": "EST"
},
"daylightSavingsTimeZone": {
"zoneOffset": "-04:00",
"zoneAbbreviation": "EDT"
},
"siteUsesDaylightSavingsTime": true
},
"geoLocation": {
"geogLocation": {
"srs": "EPSG:4326",
"latitude": 44.74977166,
"longitude": -71.63120018
},
"localSiteXY": []
},
"note": [],
"siteType": [],
"siteProperty": [
{
"value": "ST",
"name": "siteTypeCd"
},
{
"value": "01080101",
"name": "hucCd"
},
{
"value": "33",
"name": "stateCd"
},
{
"value": "33007",
"name": "countyCd"
}
]
},
"variable": {
"variableCode": [
{
"value": "00060",
"network": "NWIS",
"vocabulary": "NWIS:UnitValues",
"variableID": 45807197,
"default": true
}
],
"variableName": "Streamflow, ft³/s",
"variableDescription": "Discharge, cubic feet per second",
"valueType": "Derived Value",
"unit": {
"unitCode": "ft3/s"
},
"options": {
"option": [
{
"name": "Statistic",
"optionCode": "00000"
}
]
},
"note": [],
"noDataValue": -999999,
"variableProperty": [],
"oid": "45807197"
},
"values": [
{
"value": [
{
"value": "2550",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T18:00:00.000-05:00"
},
{
"value": "2550",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T18:15:00.000-05:00"
},
{
"value": "2520",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T18:30:00.000-05:00"
},
{
"value": "2520",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T18:45:00.000-05:00"
},
{
"value": "2520",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T19:00:00.000-05:00"
},
{
"value": "2520",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T19:15:00.000-05:00"
},
{
"value": "2500",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T19:30:00.000-05:00"
},
{
"value": "2500",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T19:45:00.000-05:00"
},
{
"value": "2500",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T20:00:00.000-05:00"
},
{
"value": "2500",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T20:15:00.000-05:00"
},
{
"value": "2500",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T20:30:00.000-05:00"
},
{
"value": "2490",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T20:45:00.000-05:00"
},
{
"value": "2490",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T21:00:00.000-05:00"
},
{
"value": "2490",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T21:15:00.000-05:00"
},
{
"value": "2490",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T21:30:00.000-05:00"
},
{
"value": "2490",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T21:45:00.000-05:00"
},
{
"value": "2470",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T22:00:00.000-05:00"
},
{
"value": "2470",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T22:15:00.000-05:00"
},
{
"value": "2450",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T22:30:00.000-05:00"
},
{
"value": "2450",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T22:45:00.000-05:00"
},
{
"value": "2450",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T23:00:00.000-05:00"
},
{
"value": "2450",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T23:15:00.000-05:00"
},
{
"value": "2450",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T23:30:00.000-05:00"
},
{
"value": "2450",
"qualifiers": [
"P"
],
"dateTime": "2017-11-05T23:45:00.000-05:00"
},
{
"value": "2450",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T00:00:00.000-05:00"
},
{
"value": "2470",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T00:15:00.000-05:00"
},
{
"value": "2470",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T00:30:00.000-05:00"
},
{
"value": "2470",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T00:45:00.000-05:00"
},
{
"value": "2450",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T01:00:00.000-05:00"
},
{
"value": "2450",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T01:15:00.000-05:00"
},
{
"value": "2470",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T01:30:00.000-05:00"
},
{
"value": "2470",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T01:45:00.000-05:00"
},
{
"value": "2470",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T02:00:00.000-05:00"
},
{
"value": "2490",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T02:15:00.000-05:00"
},
{
"value": "2490",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T02:30:00.000-05:00"
},
{
"value": "2500",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T02:45:00.000-05:00"
},
{
"value": "2500",
"qualifiers": [
"P"
],
"dateTime": "2017-11-06T03:00:00.000-05:00"
}
],
"qualifier": [
{
"qualifierCode": "P",
"qualifierDescription": "Provisional data subject to revision.",
"qualifierID": 0,
"network": "NWIS",
"vocabulary": "uv_rmk_cd"
}
],
"qualityControlLevel": [],
"method": [
{
"methodDescription": "",
"methodID": 66577
}
],
"source": [],
"offset": [],
"sample": [],
"censorCode": []
}
],
"name": "USGS:01129500:00060:00000"
}
]
},
"nil": false,
"globalScope": true,
"typeSubstituted": false
}
How do I grab all of the information with the label "value" and store these numbers into a data structure I can then perform functions on?
Thanks
That question has nothing to do with busy parsing and the json itself isn't that large. You could just iterate over $data['value']['timeSeries'][0]['values'][0]['value'] and extract everything you need.
$data = json_decode($json, true);
$t = [];
foreach ($data['value']['timeSeries'][0]['values'][0]['value'] as $item) {
$t[] = $item['value'];
}
If you need different keys, just have a look at the json data and modify the loop. If you need unique keys, use array_unique on the $t var.
The naive thing to do is a simple recursive operation:
$arr = json_decode($json,true);
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr), RecursiveIteratorIterator::SELF_FIRST);
$values = [];
foreach ( $iterator as $key => $value ) {
if ($key === "value" && !is_array($value)) {
$values[] = $value;
}
}
Example: http://sandbox.onlinephpfunctions.com/code/b36d70d84926d9b5ca9989c9ba96b34fe1f2a7b6
Related
I have 2 Multiple-Arrays and I want to compare them. In the second Array I want then show with colors which value has changed, which key is new and which key is removed.
I have found a lot of different solutions, but no one function for me.
Here are my arrays:
{
"originFormation": {
"stationName": "Bern",
"sections": [{
"name": "B",
"cars": [{
"type": "LOK",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": false,
"nextPassage": false
}]
}, {
"name": "C",
"cars": [{
"type": "CAR",
"number": "1",
"class": "1",
"occupancy": "UNKNOWN",
"attributes": ["AbteilRollstuhl", "AbteilBusiness"],
"closed": false,
"previousPassage": false,
"nextPassage": true
}, {
"type": "CAR",
"number": "1",
"class": "2",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": true,
"nextPassage": true
}]
}],
"legendItems": [{
"id": "1",
"text": "1st class coach",
"refersTo": "type"
}, {
"id": "2",
"text": "2st class coach",
"refersTo": "type"
}, {
"id": "Fahrtrichtung",
"text": "Direction of travel",
"refersTo": "code"
}, {
"id": "FA",
"text": "Family Coach with play area",
"refersTo": "type"
}, {
"id": "AbteilRollstuhl",
"text": "Wheelchair space",
"refersTo": "code"
}, {
"id": "AbteilVeloPl",
"text": "Bicycle loading: Without reservation",
"refersTo": "code"
}, {
"id": "LK",
"text": "Locomotive",
"refersTo": "type"
}, {
"id": "WR",
"text": "Restaurant 1st and 2nd class",
"refersTo": "type"
}, {
"id": "AbteilBusiness",
"text": "Business zone in 1st class: Reservation possible",
"refersTo": "code"
},
{
"id": "HFS_WG_NUM",
"text": "Coach",
"refersTo": "code"
}, {
"id": "KD",
"text": "No passage",
"refersTo": "type"
}
],
"info": {
"title": "Changes to the composition of the train",
"formationChanges": []
}
}
}
Array2:
{
"originFormation": {
"stationName": "Bern",
"sections": [
{
"name": "B",
"cars": [
{
"type": "LOK",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": false,
"nextPassage": false
}
]
},
{
"name": "C",
"cars": [
{
"type": "CAR",
"number": "12",
"class": "1",
"occupancy": "UNKNOWN",
"attributes": [
"AbteilRollstuhl",
"AbteilBusiness"
],
"closed": false,
"previousPassage": false,
"nextPassage": true
},
{
"type": "CAR",
"number": "1",
"class": "2",
"occupancy": "UNKNOWN",
"attributes": [
"AbteilStefan"
],
"closed": false,
"previousPassage": true,
"nextPassage": true
},
{
"type": "CAR",
"number": "2",
"class": "1",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": true,
"nextPassage": true
}
]
}
],
"legendItems": [
{
"id": "1",
"text": "1st class coach",
"refersTo": "type"
},
{
"id": "2",
"text": "2st class coach",
"refersTo": "type"
},
{
"id": "Fahrtrichtung",
"text": "Direction of travel",
"refersTo": "code"
},
{
"id": "FA",
"text": "Family Coach with play area",
"refersTo": "type"
},
{
"id": "AbteilRollstuhl",
"text": "Wheelchair space",
"refersTo": "code"
},
{
"id": "AbteilVeloPl",
"text": "Bicycle loading: Without reservation",
"refersTo": "code"
},
{
"id": "LK",
"text": "Locomotive",
"refersTo": "type"
},
{
"id": "WR",
"text": "Restaurant 1st and 2nd class",
"refersTo": "type"
},
{
"id": "AbteilBusiness",
"text": "Business zone in 1st class: Reservation possible",
"refersTo": "code"
},
{
"id": "AbteilStefan",
"text": "Ich bin ein neues Abteil",
"refersTo": "code"
},
{
"id": "HFS_WG_NUM",
"text": "Coach",
"refersTo": "code"
},
{
"id": "KD",
"text": "No passage",
"refersTo": "type"
}
],
"info": {
"title": "Changes to the composition of the train",
"formationChanges": [
"All Changed"
]
}
}
}
My fonction to compare:
function array_diff_assoc_recursive($array1, $array2)
{
foreach($array1 as $key => $value)
{
if(is_array($value))
{
if(!isset($array2[$key]))
{
$difference[$key] = $value;
}
elseif(!is_array($array2[$key]))
{
$difference[$key] = "<b>".$value."</b>";
}
else
{
$new_diff = array_diff_assoc_recursive($value, $array2[$key]);
if($new_diff != FALSE)
{
$difference[$key] = $new_diff;
}
}
}
elseif(!isset($array2[$key]) || $array2[$key] != $value)
{
$difference[$key] = "<b>".$value."</b>";
}
}
return !isset($difference) ? 0 : $difference;
}
var_dump(array_diff_assoc_recursive($array2, $array1));
This difference i get:
[originformation][sections][1][cars][0][number] -> newValue 12
[originformation][sections][1][cars][1][attributes] -> newValue AbteilStefan
[originformation][sections][1][cars][2] -> all Attributes are new
[originformation][legendItems][9][id] -> newValue AbteilStefan
[originformation][legendItems][9][text] -> newValue Ich bin ein neues Abteil
[originformation][legendItems][10] -> all Attributes are new
[originformation][legendItems][11] -> all Attributes are new
[originformation][info][formationChanges][0] => newValue All Changed
The difference i expected
[originformation][sections][1][cars][0][number] -> newValue 12
[originformation][sections][1][cars][1] -> all Attributes are new
[originformation][legendItems][9] -> all Attributes are new
[originformation][info][formationChanges][0] => newValue All Changed
Problem
My function doesn't see, that car in Array2 I put in a complete new car and also a complete new legendItem and the rest is still the same.
Does someone know how I can compare the arrays, that he doesn't check the order of the attributes on the same level?
I want to create booking and generate PNR using amadeus flight booking API.
I have follow 3 step to create booking and generate PNR
Flight Offers Search API using bellow API
https://developers.amadeus.com/self-service/category/air/api-doc/flight-offers-search/api-reference
Flight Offers Price API using bellow API
https://developers.amadeus.com/self-service/category/air/api-doc/flight-offers-price/api-reference
Flight Create Orders API using bellow API
https://developers.amadeus.com/self-service/category/air/api-doc/flight-create-orders/api-reference
When i serach with city with one way thip and choose specific offer and puting passenger details
to create booking and generat PNR. then PNR will generate successfully
i am using bellow API to generate PNR
https://developers.amadeus.com/self-service/category/air/api-doc/flight-create-orders/api-reference
this is my request json
"data": {
"type": "flight-order",
"flightOffers": [
{
"type": "flight-offer",
"id": "5",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"paymentCardRequired": false,
"lastTicketingDate": "2021-07-23",
"itineraries": [
{
"segments": [
{
"departure": {
"iataCode": "JFK",
"terminal": "5",
"at": "2021-07-30T09:20:00"
},
"arrival": {
"iataCode": "FLL",
"terminal": "3",
"at": "2021-07-30T12:30:00"
},
"carrierCode": "B6",
"number": "201",
"aircraft": {
"code": "320"
},
"operating": {
"carrierCode": "B6"
},
"duration": "PT3H10M",
"id": "91",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 155,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
},
{
"departure": {
"iataCode": "FLL",
"terminal": "3",
"at": "2021-07-30T16:25:00"
},
"arrival": {
"iataCode": "LAX",
"terminal": "5",
"at": "2021-07-30T18:49:00"
},
"carrierCode": "B6",
"number": "1301",
"aircraft": {
"code": "32S"
},
"operating": {
"carrierCode": "B6"
},
"duration": "PT5H24M",
"id": "92",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 253,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
}
],
"duration": "PT12H29M"
}
],
"price": {
"currency": "USD",
"total": "276.20",
"base": "235.35",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
},
{
"amount": "0.00",
"type": "FORM_OF_PAYMENT"
}
],
"grandTotal": "276.20",
"billingCurrency": "USD"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": false
},
"validatingAirlineCodes": [
"B6"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "USD",
"total": "276.20",
"base": "235.35",
"taxes": [
{
"amount": "8.60",
"code": "ZP"
},
{
"amount": "5.60",
"code": "AY"
},
{
"amount": "17.65",
"code": "US"
},
{
"amount": "9.00",
"code": "XF"
}
],
"refundableTaxes": "40.85"
},
"fareDetailsBySegment": [
{
"segmentId": "91",
"cabin": "ECONOMY",
"fareBasis": "OL7AUEL1",
"brandedFare": "DN",
"class": "L",
"includedCheckedBags": {
"quantity": 0
}
},
{
"segmentId": "92",
"cabin": "ECONOMY",
"fareBasis": "ZI3PUEL1",
"brandedFare": "DN",
"class": "L",
"includedCheckedBags": {
"quantity": 0
}
}
]
}
]
}
],
"travelers": [
{
"id": 1,
"dateOfBirth": "**********",
"name": {
"firstName": "**********",
"lastName": "**********"
},
"gender": "**********"
}
],
"contacts": [
{
"addresseeName": {
"firstName": "**********",
"lastName": "**********"
},
"purpose": "STANDARD",
"emailAddress": "**********",
"phones": [
{
"deviceType": "MOBILE",
"countryCallingCode": "**",
"number": "**********"
}
],
"address": {
"lines": [
"**********"
],
"postalCode": "**********",
"cityName": "**********",
"countryCode": "**********"
}
}
],
"remarks": {
"general": [
{
"subType": "GENERAL_MISCELLANEOUS",
"text": "ONLINE BOOKING FROM INCREIBLE VIAJES"
}
]
},
"ticketingAgreement": {
"option": "DELAY_TO_CANCEL",
"delay": "6D"
}
}
}
and this is my API response.
PNR generated successfully/
stdClass Object
(
[warnings] => Array
(
[0] => stdClass Object
(
[status] => 200
[code] => 0
[title] => ContactInfoSsrNotAddedToBookingWarning
[detail] => Unable to create some contact information SSR. Email and mobile phone number required.
)
)
[data] => stdClass Object
(
[type] => flight-order
[id] => eJzTd9f3cg228PcBAAskAls%3D
[associatedRecords] => Array
(
[0] => stdClass Object
(
[reference] => JES8OL
[creationDate] => 2021-07-23T10:28:00.000
[originSystemCode] => GDS
[flightOfferId] => 5
)
)
[flightOffers] => Array
(
[0] => stdClass Object
(
[type] => flight-offer
[id] => 5
[source] => GDS
[nonHomogeneous] =>
[lastTicketingDate] => 2021-07-23
[itineraries] => Array
But when i search with differnt city and follow the same step.
this is my request json
data": {
"type": "flight-order",
"flightOffers": [
{
"type": "flight-offer",
"id": "3",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"paymentCardRequired": false,
"lastTicketingDate": "2021-07-28",
"itineraries": [
{
"segments": [
{
"departure": {
"iataCode": "DEL",
"terminal": "3",
"at": "2021-08-05T05:35:00"
},
"arrival": {
"iataCode": "BLR",
"at": "2021-08-05T08:20:00"
},
"carrierCode": "AI",
"number": "803",
"aircraft": {
"code": "32B"
},
"operating": {
"carrierCode": "AI"
},
"duration": "PT2H45M",
"id": "17",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 145,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
}
],
"duration": "PT2H45M"
},
{
"segments": [
{
"departure": {
"iataCode": "BLR",
"at": "2021-08-10T17:10:00"
},
"arrival": {
"iataCode": "DEL",
"terminal": "3",
"at": "2021-08-10T19:55:00"
},
"carrierCode": "AI",
"number": "501",
"aircraft": {
"code": "32B"
},
"operating": {
"carrierCode": "AI"
},
"duration": "PT2H45M",
"id": "42",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 145,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
}
],
"duration": "PT2H45M"
}
],
"price": {
"currency": "USD",
"total": "88.59",
"base": "68.00",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
},
{
"amount": "0.00",
"type": "FORM_OF_PAYMENT"
}
],
"grandTotal": "88.59",
"billingCurrency": "USD"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": true
},
"validatingAirlineCodes": [
"AI"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "USD",
"total": "88.59",
"base": "68.00",
"taxes": [
{
"amount": "6.34",
"code": "P2"
},
{
"amount": "3.78",
"code": "IN"
},
{
"amount": "3.63",
"code": "K3"
},
{
"amount": "2.28",
"code": "WO"
},
{
"amount": "4.56",
"code": "YR"
}
],
"refundableTaxes": "17.19"
},
"fareDetailsBySegment": [
{
"segmentId": "17",
"cabin": "ECONOMY",
"fareBasis": "SAP8",
"class": "S",
"includedCheckedBags": {
"weight": 25,
"weightUnit": "KG"
}
},
{
"segmentId": "42",
"cabin": "ECONOMY",
"fareBasis": "SAP8",
"class": "S",
"includedCheckedBags": {
"weight": 25,
"weightUnit": "KG"
}
}
]
}
]
}
],
"travelers": [
{
"id": 1,
"dateOfBirth": "**********",
"name": {
"firstName": "**********",
"lastName": "**********"
},
"gender": "**********"
}
],
"contacts": [
{
"addresseeName": {
"firstName": "**********",
"lastName": "**********"
},
"purpose": "STANDARD",
"emailAddress": "**********",
"phones": [
{
"deviceType": "**********",
"countryCallingCode": "**",
"number": "**********"
}
],
"address": {
"lines": [
"**********"
],
"postalCode": "**********",
"cityName": "**********",
"countryCode": "**********"
}
}
],
"remarks": {
"general": [
{
"subType": "GENERAL_MISCELLANEOUS",
"text": "ONLINE BOOKING FROM INCREIBLE VIAJES"
}
]
},
"ticketingAgreement": {
"option": "DELAY_TO_CANCEL",
"delay": "6D"
}
}
and this is my API response.
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[status] => 400
[code] => 34651
[title] => SEGMENT SELL FAILURE
[detail] => Could not sell segment 2
[source] => stdClass Object
(
[pointer] => /data/flightOffers[0]/itineraries[1]/segments[0]
)
)
)
)
Can you please guide me what is the issue.I am using amadeus test API credential.Also guide me how to solve the issue
Thank You
You usually get this error when trying to book a seat that is not available anymore. You are using the test environment, it means everybody else using Amadeus for Developers in test can be trying to book the same seat.
Try with another flight and don't forget to perform the Flight Offers Price before booking.
PS: I see some personal data in the example above, you should edit your post to remove it.
When i call this API,
{{base_url}}index.php/rest/V1/configurable-products/:sku/options/all
I am getting a response like this,
[
{
"id": 9,
"attribute_id": "93",
"label": "Color",
"position": 0,
"values": [
{
"value_index": 15
},
{
"value_index": 16
},
{
"value_index": 17
}
],
"product_id": 19
},
{
"id": 10,
"attribute_id": "176",
"label": "side",
"position": 1,
"values": [
{
"value_index": 18
},
{
"value_index": 19
}
],
"product_id": 19
}
]
But i want label for all these value_indexes.Could i get all these values in a single request
There is an pi for getting all the labels,
{{base_url}}/index.php/rest/V1/products/attributes/:attribute_id/options
Ex:
{{base_url}}/index.php/rest/V1/products/attributes/93/options
will return
[
{
"label": " ",
"value": ""
},
{
"label": "green",
"value": "12"
},
{
"label": "yellow",
"value": "13"
},
{
"label": "red",
"value": "14"
}
]
You can use this endpoint to fetch multiple attribute sets in a single request
/rest/V1/products/attributes
example:
{domain}/rest/V1/products/attributes?search_criteria[filter_groups][0][filters][0][field]=attribute_id&search_criteria[filter_groups][0][filters][0][value]=93,138&search_criteria[filter_groups][0][filters][0][condition_type]=in
response:
"items": [
{
"is_wysiwyg_enabled": false,
"is_html_allowed_on_front": false,
"used_for_sort_by": false,
"is_filterable": true,
"is_filterable_in_search": false,
"is_used_in_grid": true,
"is_visible_in_grid": false,
"is_filterable_in_grid": true,
"position": 0,
"apply_to": [
"simple",
"virtual",
"configurable"
],
"is_searchable": "1",
"is_visible_in_advanced_search": "1",
"is_comparable": "1",
"is_used_for_promo_rules": "0",
"is_visible_on_front": "0",
"used_in_product_listing": "0",
"is_visible": true,
"scope": "global",
"attribute_id": 93,
"attribute_code": "color",
"frontend_input": "select",
"entity_type_id": "4",
"is_required": false,
"options": [
{
"label": " ",
"value": ""
},
{
"label": "blue",
"value": "8"
},
{
"label": "red",
"value": "9"
},
{
"label": "black",
"value": "10"
},
{
"label": "white",
"value": "11"
}
],
"is_user_defined": true,
"default_frontend_label": "Color",
"frontend_labels": [],
"backend_type": "int",
"source_model": "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table",
"default_value": "",
"is_unique": "0",
"validation_rules": []
},
{
"is_wysiwyg_enabled": false,
"is_html_allowed_on_front": true,
"used_for_sort_by": false,
"is_filterable": false,
"is_filterable_in_search": false,
"is_used_in_grid": true,
"is_visible_in_grid": true,
"is_filterable_in_grid": true,
"position": 0,
"apply_to": [],
"is_searchable": "0",
"is_visible_in_advanced_search": "0",
"is_comparable": "0",
"is_used_for_promo_rules": "0",
"is_visible_on_front": "0",
"used_in_product_listing": "0",
"is_visible": true,
"scope": "global",
"attribute_id": 138,
"attribute_code": "simple_size",
"frontend_input": "select",
"entity_type_id": "4",
"is_required": true,
"options": [
{
"label": " ",
"value": ""
},
{
"label": "small",
"value": "12"
},
{
"label": "medium",
"value": "13"
},
{
"label": "large",
"value": "14"
}
],
"is_user_defined": true,
"default_frontend_label": "simple_size",
"frontend_labels": [
{
"store_id": 1,
"label": "Size"
}
],
"backend_type": "int",
"source_model": "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table",
"default_value": "",
"is_unique": "0",
"validation_rules": []
}
],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "attribute_id",
"value": "93,138",
"condition_type": "in"
}
]
}
]
},
"total_count": 2
}
I have a mapping like this
{
"settings": {
"analysis": {
"filter": {
"nGramFilter": {
"type": "nGram",
"min_gram": 3,
"max_gram": 20,
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
},
"email" : {
"type" : "pattern_capture",
"preserve_original" : 1,
"patterns" : [
"([^#]+)",
"(\\p{L}+)",
"(\\d+)",
"#(.+)"
]
},
"number" : {
"type" : "pattern_capture",
"preserve_original" : 1,
"patterns" : [
"([^+-]+)",
"(\\d+)"
]
},
"edgeNGramFilter": {
"type": "nGram",
"min_gram": 1,
"max_gram": 10,
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
"analyzer": {
"nGramAnalyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"nGramFilter"
]
},
"whitespaceAnalyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
},
"email" : {
"tokenizer" : "uax_url_email",
"filter" : [
"email",
"lowercase",
"unique"
]
},
"number" : {
"tokenizer" : "whitespace",
"filter" : [ "number", "unique" ]
},
"edgeNGramAnalyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"edgeNGramFilter"
]
}
}
}
},
"users": {
"mappings": {
"user_profiles": {
"properties": {
"firstName": {
"type": "string",
"analyzer": "nGramAnalyzer",
"search_analyzer": "whitespaceAnalyzer"
},
"lastName": {
"type": "string",
"analyzer": "nGramAnalyzer",
"search_analyzer": "whitespaceAnalyzer"
},
"email": {
"type": "string",
"analyzer": "email",
"search_analyzer": "whitespaceAnalyzer"
},
"score" : {
"type": "string"
},
"homeLandline": {
"type": "string",
"analyzer": "number",
"search_analyzer": "whitespaceAnalyzer"
},
"dob": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"mobile": {
"type": "integer"
},
"residenceCity": {
"type": "string",
"analyzer": "edgeNGramAnalyzer",
"search_analyzer": "whitespaceAnalyzer"
},
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
}
}
}
}
}
I can get the score as integer as well as "NA" so I mapped the type as string but while posting data to the index i am getting Number Format Exception.
For Example:
if I post first data as integer and followed by "NA". I am getting these exception.
while checking my log file I am getting this errors:
[2016-08-29 15:19:01] elasticlog.WARNING: Response ["{\"error\":{\"root_cause\":[{\"type\":\"mapper_parsing_exception\",\"reason\":\"failed
to parse
[score]\"}],\"type\":\"mapper_parsing_exception\",\"reason\":\"failed
to parse
[score]\",\"caused_by\":{\"type\":\"number_format_exception\",\"reason\":\"For
input string: \"NH\"\"}},\"status\":400}"] []
Your mapping is incorrect. It should be, assuming, users is the index name and user_profiles is the type:
{
"users": {
"mappings": {
"user_profiles": {
"properties": {
"score": {
"type": "string"
}
}
}
}
}
}
You have a missing mappings before user_profiles.
I'm trying to retrieve the responses for a particular survey from Survey Monkey using the get_responses endpoint which only retrieves the "col" and "row" ids.
{
"status": 0,
"data": [
{
"respondent_id": "4165059283",
"questions": [
{
"answers": [
{
"text": "04/11/1990",
"row": "9333771686"
}
],
"question_id": "842633241"
},
{
"answers": [
{
"row": "9333771693"
},
{
"text": "aa",
"row": "9333771691"
}
],
"question_id": "842633242"
},
{
"answers": [
{
"col": "9333771714",
"row": "9333771713"
},
{
"col": "9333771717",
"row": "9333771712"
},
{
"col": "9333771714",
"row": "9333771711"
},
{
"col": "9333771717",
"row": "9333771710"
},
{
"col": "9333771717",
"row": "9333771709"
},
{
"col": "9333771716",
"row": "9333771708"
},
{
"col": "9333771714",
"row": "9333771707"
},
{
"col": "9333771716",
"row": "9333771706"
},
{
"col": "9333771716",
"row": "9333771705"
},
{
"col": "9333771715",
"row": "9333771704"
},
{
"col": "9333771715",
"row": "9333771703"
},
{
"col": "9333771714",
"row": "9333771702"
},
{
"text": "aa",
"row": "0"
}
],
"question_id": "842633243"
},
{
"answers": [
{
"col": "9333771729",
"row": "9333771726"
},
{
"col": "9333771727",
"row": "9333771725"
},
{
"col": "9333771727",
"row": "9333771724"
},
{
"text": "aaa",
"row": "0"
}
],
"question_id": "842633244"
},
]
}
]
}
I can see that these id's correlate to a question and answer from the get_survey_details endpoint..
But how on earth do you filter the get_survey_details response to only show the question/answer that the respondent has given rather than retrieve everything? I've tried adding to the $params in the class as shown but the request still gives everything back... so clearly this isn't possible or I'm going about it in completely the wrong way:
public function getSurveyDetails($surveyId){
//original $params
//$params = array('survey_id'=>$surveyId);
$params = array(
'survey_id'=>$surveyId,
'pages'=>array(
'questions' => array (
'answers' => array (
'answer_id' => '9333771686',
)
),
)
);
return $this->run('surveys/get_survey_details', $params);
}