My JSON url is http://api.kivaws.org/v1/loans/search.json?status=fundraising
My Objective- code displays page_size : 20 using the following code
NSData *allCourseData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://api.kivaws.org/v1/loans/search.json?status=fundraising"]];
NSError *error;
NSMutableDictionary *JsonObject = [NSJSONSerialization
JSONObjectWithData:allCourseData options:NSJSONReadingMutableContainers
error:&error];
//NSLog(#"json object is: - %#", JsonObject);
//Print Page size
NSLog(#"Page size is %#", [[JsonObject objectForKey:#"paging"] objectForKey:#"page_size"]);
My problem is how do i loop to Loans array to display the following
Example it will display name, display ALL languages, status so output will look like
============================
Name : "Maria Luisa"
languages: es,en
status : "fundraising"
sector : "Retail"
location
country_code : "NI"
Name : "Florence"
languages: en
status : "fundraising"
sector : "Retail"
location
country_code : "KE"
MyJSON Feed
{
"paging": {
"page": 1,
"total": 7279,
"page_size": 20,
"pages": 364
},
"loans": [
{
"id": 941933,
"name": "Maria Luisa",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969857,
"template_id": 1
},
"activity": "General Store",
"sector": "Retail",
"use": "to buy rice, chicken, sausages, corn, beans, and sugar.",
"location": {
"country_code": "NI",
"country": "Nicaragua",
"town": "Esteli",
"geo": {
"level": "town",
"pairs": "13.166667 -86.333333",
"type": "point"
}
},
"partner_id": 176,
"posted_date": "2015-09-04T09:20:02Z",
"planned_expiration_date": "2015-10-04T09:20:02Z",
"loan_amount": 600,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942181,
"name": "Florence",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970181,
"template_id": 1
},
"activity": "Retail",
"sector": "Retail",
"use": "to buy more stocks of maize.",
"location": {
"country_code": "KE",
"country": "Kenya",
"town": "Bondo",
"geo": {
"level": "town",
"pairs": "1 38",
"type": "point"
}
},
"partner_id": 138,
"posted_date": "2015-09-04T09:10:08Z",
"planned_expiration_date": "2015-10-04T09:10:08Z",
"loan_amount": 200,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942146,
"name": "Naziha",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970129,
"template_id": 1
},
"activity": "Fruits & Vegetables",
"sector": "Food",
"use": "to increase her merchandise and diversify the products in her shop.",
"location": {
"country_code": "LB",
"country": "Lebanon",
"town": "Ain Al Helwi",
"geo": {
"level": "town",
"pairs": "33.833333 35.833333",
"type": "point"
}
},
"partner_id": 77,
"posted_date": "2015-09-04T09:10:02Z",
"planned_expiration_date": "2015-10-04T09:10:02Z",
"loan_amount": 2500,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942180,
"name": "Sokean's Group",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970180,
"template_id": 1
},
"activity": "Home Appliances",
"sector": "Personal Use",
"themes": [
"Water and Sanitation"
],
"use": "to buy a water filter to provide safe drinking water for her family.",
"location": {
"country_code": "KH",
"country": "Cambodia",
"town": "Kandal",
"geo": {
"level": "town",
"pairs": "13 105",
"type": "point"
}
},
"partner_id": 311,
"posted_date": "2015-09-04T09:00:05Z",
"planned_expiration_date": "2015-10-04T09:00:05Z",
"loan_amount": 100,
"borrower_count": 2,
"lender_count": 0,
"bonus_credit_eligibility": false,
"tags": [
{
"name": "volunteer_like"
}
]
},
{
"id": 941931,
"name": "Lucia Ingrid",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969852,
"template_id": 1
},
"activity": "Personal Housing Expenses",
"sector": "Housing",
"themes": [
"Conflict Zones"
],
"use": "to invest in: electric wires, a fuse box, sockets, and labor to install electricity in her home.",
"location": {
"country_code": "SV",
"country": "El Salvador",
"geo": {
"level": "country",
"pairs": "13.833333 -88.916667",
"type": "point"
}
},
"partner_id": 81,
"posted_date": "2015-09-04T09:00:03Z",
"planned_expiration_date": "2015-10-04T09:00:03Z",
"loan_amount": 500,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 941930,
"name": "La Manzanita Group",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969849,
"template_id": 1
},
"activity": "Fruits & Vegetables",
"sector": "Food",
"use": "to invest in buying papayas and nance berries in bulk.",
"location": {
"country_code": "NI",
"country": "Nicaragua",
"town": "Masaya",
"geo": {
"level": "town",
"pairs": "11.966667 -86.1",
"type": "point"
}
},
"partner_id": 120,
"posted_date": "2015-09-04T08:50:02Z",
"planned_expiration_date": "2015-10-04T08:50:02Z",
"loan_amount": 450,
"borrower_count": 3,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 941926,
"name": "Manuel",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969843,
"template_id": 1
},
"activity": "Property",
"sector": "Housing",
"use": "to buy two acres of land.",
"location": {
"country_code": "GT",
"country": "Guatemala",
"town": "Solola",
"geo": {
"level": "town",
"pairs": "14.666667 -91.25",
"type": "point"
}
},
"partner_id": 246,
"posted_date": "2015-09-04T08:10:02Z",
"planned_expiration_date": "2015-10-04T08:10:02Z",
"loan_amount": 800,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": [
{
"name": "volunteer_like"
}
]
},
{
"id": 942158,
"name": "Tahira",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 150,
"basket_amount": 0,
"image": {
"id": 1969161,
"template_id": 1
},
"activity": "Sewing",
"sector": "Services",
"themes": [
"Underfunded Areas"
],
"use": "buy a new sewing machine for her clothes sewing center.",
"location": {
"country_code": "PK",
"country": "Pakistan",
"town": "Multan",
"geo": {
"level": "town",
"pairs": "30.195556 71.475278",
"type": "point"
}
},
"partner_id": 247,
"posted_date": "2015-09-04T07:00:05Z",
"planned_expiration_date": "2015-10-04T07:00:05Z",
"loan_amount": 400,
"borrower_count": 1,
"lender_count": 5,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 942166,
"name": "Sareoun's Group",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970161,
"template_id": 1
},
"activity": "Home Appliances",
"sector": "Personal Use",
"themes": [
"Water and Sanitation"
],
"use": "to buy a water filter to provide safe drinking water for their family.\t.",
"location": {
"country_code": "KH",
"country": "Cambodia",
"town": "Kandal",
"geo": {
"level": "town",
"pairs": "13 105",
"type": "point"
}
},
"partner_id": 311,
"posted_date": "2015-09-04T07:00:05Z",
"planned_expiration_date": "2015-10-04T07:00:05Z",
"loan_amount": 225,
"borrower_count": 5,
"lender_count": 0,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 942156,
"name": "Aiza",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 75,
"basket_amount": 0,
"image": {
"id": 1970147,
"template_id": 1
},
"activity": "Farming",
"sector": "Agriculture",
"use": "to buy fertilizers and other farm supplies",
"location": {
"country_code": "PH",
"country": "Philippines",
"town": "Kalibo, Aklan",
"geo": {
"level": "town",
"pairs": "13 122",
"type": "point"
}
},
"partner_id": 145,
"posted_date": "2015-09-04T07:00:03Z",
"planned_expiration_date": "2015-10-04T07:00:03Z",
"loan_amount": 225,
"borrower_count": 1,
"lender_count": 2,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942160,
"name": "Magu Group",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970122,
"template_id": 1
},
"activity": "Used Clothing",
"sector": "Clothing",
"use": "to buy fast moving second hand clothes to meet her customer requirement.",
"location": {
"country_code": "TZ",
"country": "Tanzania",
"town": "Dar es Salaam",
"geo": {
"level": "town",
"pairs": "-6.8 39.283333",
"type": "point"
}
},
"partner_id": 87,
"posted_date": "2015-09-04T07:00:02Z",
"planned_expiration_date": "2015-10-04T07:00:02Z",
"loan_amount": 525,
"borrower_count": 2,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942142,
"name": "Mwanamiraji",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970130,
"template_id": 1
},
"activity": "Food Stall",
"sector": "Food",
"use": "to purchase a stock of tomatoes, onions, mangoes and green vegetables for resale",
"location": {
"country_code": "KE",
"country": "Kenya",
"town": "Tiribe",
"geo": {
"level": "town",
"pairs": "1 38",
"type": "point"
}
},
"partner_id": 164,
"posted_date": "2015-09-04T06:30:04Z",
"planned_expiration_date": "2015-10-04T06:30:04Z",
"loan_amount": 200,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 940065,
"name": "Tubogorane Group",
"description": {
"languages": [
"fr",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1967147,
"template_id": 1
},
"activity": "Food",
"sector": "Food",
"themes": [
"Conflict Zones"
],
"use": "to increase his working capital and buy a large quantity of fruit and cheese for sale.",
"location": {
"country_code": "BI",
"country": "Burundi",
"town": "Bujumbura",
"geo": {
"level": "town",
"pairs": "-3.5 30",
"type": "point"
}
},
"partner_id": 162,
"posted_date": "2015-09-04T06:20:05Z",
"planned_expiration_date": "2015-10-04T06:20:05Z",
"loan_amount": 3050,
"borrower_count": 19,
"lender_count": 0,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 940076,
"name": "Wend Loiim Taore 2 Group",
"description": {
"languages": [
"fr",
"en"
]
},
"status": "fundraising",
"funded_amount": 50,
"basket_amount": 0,
"image": {
"id": 1967173,
"template_id": 1
},
"activity": "Clothing Sales",
"sector": "Clothing",
"use": "to buy pagnes (traditional, wrap-around clothing) and soap for sale.",
"location": {
"country_code": "BF",
"country": "Burkina Faso",
"town": "Ouagadougou Boulmiougou",
"geo": {
"level": "town",
"pairs": "13 -2",
"type": "point"
}
},
"partner_id": 398,
"posted_date": "2015-09-04T06:20:05Z",
"planned_expiration_date": "2015-10-04T06:20:05Z",
"loan_amount": 1850,
"borrower_count": 5,
"lender_count": 2,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 942145,
"name": "Adham",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 25,
"basket_amount": 0,
"image": {
"id": 1970127,
"template_id": 1
},
"activity": "Barber Shop",
"sector": "Services",
"use": "to buy new salon equipment.",
"location": {
"country_code": "PS",
"country": "Palestine",
"town": "Bethlehem",
"geo": {
"level": "town",
"pairs": "31.92157 35.203285",
"type": "point"
}
},
"partner_id": 289,
"posted_date": "2015-09-04T06:10:04Z",
"planned_expiration_date": "2015-10-04T06:10:04Z",
"loan_amount": 3000,
"borrower_count": 1,
"lender_count": 2,
"bonus_credit_eligibility": false,
"tags": [
{
"name": "user_favorite"
}
]
},
{
"id": 941929,
"name": "Silvia Yesenia",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969848,
"template_id": 1
},
"activity": "Retail",
"sector": "Retail",
"themes": [
"Conflict Zones"
],
"use": " to buy vegetables, legumes, staple grains and meat, amongst other items, to offer a better service to her customers",
"location": {
"country_code": "SV",
"country": "El Salvador",
"geo": {
"level": "country",
"pairs": "13.833333 -88.916667",
"type": "point"
}
},
"partner_id": 81,
"posted_date": "2015-09-04T06:10:03Z",
"planned_expiration_date": "2015-10-04T06:10:03Z",
"loan_amount": 500,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
}
]
}
Well the loans array is in the top-level JSON object, so:
NSArray *loans = jsonObject[#"loans"];
for (NSDictionary *loan in loans) {
NSNumber *ident = loan[#"id"];
NSString *name = loan[#"name"];
NSDictionary *description = loan[#"description"];
NSDictionary *location = loan[#"location"];
NSString *country = location[#"country"];
// etc.
}
NSData *allCourseData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://api.kivaws.org/v1/loans/search.json?status=fundraising"]];
NSError *error;
NSMutableDictionary *JsonObject = [NSJSONSerialization
JSONObjectWithData:allCourseData options:NSJSONReadingMutableContainers
error:&error];
// Get loans array from JsonObject
NSArray *loanJsonObject = JsonObject[#"loans"];
// Create a new loans array for store the new items
NSMutableArray *newLoans = [NSMutableArray array];
// Loop loanJsonObject to get items and create new ones
// for then store them in the new loans array
for (NSDictionary *loan in loanJsonObject) {
NSDictionary *newLoan = #{
#"name": loan[#"name"],
#"status": loan[#"status"],
#"sector": loan[#"sector"],
#"languages": loan[#"description"][#"languages"],
#"location": #{
#"country": loan[#"location"][#"country"],
#"geo": #{
#"pairs": loan[#"location"][#"geo"][#"pairs"]
}
}
};
[newLoans addObject:newLoan];
}
// the new loans
NSLog(#"newLoans: %#", newLoans);
well your loans object is an array of dictionaries.
By [JsonObject objectForKey:#"loans"] you are getting an array.
then you need to iterate for desired result.
NSArray *arrloans = [JsonObject objectForKey:#"loans"];
for (NSDictionary *dicloans in arrloans) {
NSString *name = [JsonObject objectForKey:#"name"];
NSString *countryCode = [[JsonObject objectForKey:#"location"]objectForKey:#"country_code"]; }
Related
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);
});
i am using mongoose currently for my project and i using mongoose find to query document that fit 100% exactly with what i define in the object. This is my router define:
router.get('/warned-students/:classname/:schoolYear/:semester', get_warned_students)
this is the link i typed:
http://localhost:5000/students/warned-students/k61caclc1/2016/1
as you can see, it received 3 params classname, schoolYear and semester. classname is k61clc1, choolYear is 2016 and semester is 1.
and this is my controller
const Student = require('../models/student')
exports.get_warned_students = (req, res, next) => {
const { classname, schoolYear, semester } = req.params
Student.find({
classname,
'accademicTrainningList.schoolYear': schoolYear,
'accademicTrainningList.semester': semester,
'accademicTrainningList.classification': 'Weak'
})
.exec()
.then(students => {
res.status(200).json({ size: students.length, students })
})
.catch(err => {
console.log('error in finding warned students')
res.status(500).json({ err })
})
}
it worked, but not return what i expected:
{
"size": 14,
"students": [
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e1b",
"fullname": "Trịnh Phan Anh ",
"birthday": "19/09/1997 ",
"classname": "k61caclc1",
"code": "16020508",
"vnumail": "16020508#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9dc0",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6fea9",
"score": 53,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e1e",
"fullname": "Đinh Việt Cường ",
"birthday": "13/03/1996 ",
"classname": "k61caclc1",
"code": "16022255",
"vnumail": "16022255#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9dc3",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6feac",
"score": 56,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e23",
"fullname": "Phạm Duy ",
"birthday": "17/12/1998 ",
"classname": "k61caclc1",
"code": "16020542",
"vnumail": "16020542#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Excellent",
"_id": "5f603a126d633e75884e9dc8",
"score": 90,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6feb1",
"score": 56,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e26",
"fullname": "Đặng Ngọc Đam ",
"birthday": "26/11/1998 ",
"classname": "k61caclc1",
"code": "16020518",
"vnumail": "16020518#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9dcb",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6feb4",
"score": 55,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e28",
"fullname": "Nguyễn Hải Đăng ",
"birthday": "09/08/1998 ",
"classname": "k61caclc1",
"code": "16020520",
"vnumail": "16020520#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9dcd",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6feb6",
"score": 56,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e29",
"fullname": "Nguyễn Hải Đăng ",
"birthday": "24/11/1998 ",
"classname": "k61caclc1",
"code": "16020519",
"vnumail": "16020519#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Excellent",
"_id": "5f603a126d633e75884e9dce",
"score": 90,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6feb7",
"score": 54,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e2b",
"fullname": "Đỗ Hồng Giang ",
"birthday": "29/01/1997 ",
"classname": "k61caclc1",
"code": "16020544",
"vnumail": "16020544#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9dd0",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6feb9",
"score": 57,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e36",
"fullname": "Phạm Minh Hiếu ",
"birthday": "17/10/1998 ",
"classname": "k61caclc1",
"code": "16020373",
"vnumail": "16020373#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9ddb",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6fec4",
"score": 55,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e38",
"fullname": "Nguyễn Ngọc Hòa ",
"birthday": "29/04/1997 ",
"classname": "k61caclc1",
"code": "16020566",
"vnumail": "16020566#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9ddd",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6fec6",
"score": 57,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e3b",
"fullname": "Trần Hữu Hoàn ",
"birthday": "25/11/1998 ",
"classname": "k61caclc1",
"code": "16022471",
"vnumail": "16022471#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9de0",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6fec9",
"score": 59,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e3e",
"fullname": "Nguyễn Tấn Hoàng ",
"birthday": "06/01/1998 ",
"classname": "k61caclc1",
"code": "16022261",
"vnumail": "16022261#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9de3",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6fecc",
"score": 50,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e47",
"fullname": "Nguyễn Trung Kiên ",
"birthday": "18/09/1998 ",
"classname": "k61caclc1",
"code": "16020588",
"vnumail": "16020588#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Intermediate",
"_id": "5f603a126d633e75884e9dec",
"score": 75,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6fed5",
"score": 55,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e52",
"fullname": "Nguyễn Văn Mạnh ",
"birthday": "07/07/1998 ",
"classname": "k61caclc1",
"code": "16020606",
"vnumail": "16020606#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9df7",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6fee0",
"score": 59,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e60",
"fullname": "Tạ Văn Quỳnh ",
"birthday": "06/12/1998 ",
"classname": "k61caclc1",
"code": "16020637",
"vnumail": "16020637#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Good",
"_id": "5f603a126d633e75884e9e05",
"score": 80,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Weak",
"_id": "5f603b1f3bd07d5cb4d6feee",
"score": 59,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
}
]
}
As you can see it returns results containing 1 of 3 properties but what I want is it returns only results containing all 3 properties. Thanks for helping me, have a nice day
Update:
this is what i expected: the array "accademicTrainningList" contains an element that fit all 3 property schoolYear: 2016, semester: 1 and classification: weak
{
"gender": "No Record",
"profileImage": "https://kittyinpink.co.uk/wp-content/uploads/2016/12/facebook-default-photo-male_1-1.jpg",
"_id": "5f603a126d633e75884e9e1b",
"fullname": "Trịnh Phan Anh ",
"birthday": "19/09/1997 ",
"classname": "k61caclc1",
"code": "16020508",
"vnumail": "16020508#vnu.edu.vn",
"accademicTrainningList": [
{
"semester": "1",
"classification": "Weak",
"_id": "5f603a126d633e75884e9dc0",
"score": 53,
"schoolYear": "2016"
},
{
"semester": "2",
"classification": "Good",
"_id": "5f603b1f3bd07d5cb4d6fea9",
"score": 80,
"schoolYear": "2016"
}
],
"scoreList": [],
"receiveScholarship": [],
"prizeList": [],
"scienceContestPrizeList": [],
"wentAbroad": [],
"tookTheTest": [],
"punishList": [],
"__v": 0
},
or else, if nothing match it return an empty array
It looks like $elemMatch is what you need. In your case, the query would be something like:
Student.find({
classname: "k61caclc1",
accademicTrainningList: {
$elemMatch: {
semester: "1",
schoolYear: "2016",
classification: "Weak"
}
}
})
Mongo Playground
I am trying to filter out the duplicated row after performing an include
My code
const courses = await Course.findAll({
subQuery: false,
order: [ [ 'courseID', 'ASC' ] ],
include: [
{
model: CourseAvailable,
as: 'courseAvailable',
required: false
}
]
});
Output
{
"success": true,
"data": [
{
"id": 132,
"courseID": "CSS112",
"courseName": "COMPUTER PROGRAMMING",
"required": null,
"createdAt": "2020-05-21T07:29:58.596Z",
"updatedAt": "2020-05-21T07:29:58.596Z",
"courseAvailable": [
{
"id": 508,
"courseID": "CSS112",
"semester": 2,
"credit": 3,
"totalSeat": 55,
"section": "1",
"allowedGroup": "CSS 1 A(0)",
"day": "อ.",
"start": "08.30",
"end": "10.30",
"classroom": "SCL607",
"createdAt": "2020-05-21T07:30:10.417Z",
"updatedAt": "2020-05-21T07:30:10.417Z"
},
{
"id": 509,
"courseID": "CSS112",
"semester": 2,
"credit": 3,
"totalSeat": 55,
"section": "1",
"allowedGroup": "OTHER (0)",
"day": "อ.",
"start": "08.30",
"end": "10.30",
"classroom": "SCL607",
"createdAt": "2020-05-21T07:30:10.417Z",
"updatedAt": "2020-05-21T07:30:10.417Z"
},
{
"id": 510,
"courseID": "CSS112",
"semester": 2,
"credit": 3,
"totalSeat": 55,
"section": "1",
"allowedGroup": "OTHER (0)",
"day": "อ.",
"start": "10.30",
"end": "12.30",
"classroom": "SCL703",
"createdAt": "2020-05-21T07:30:10.417Z",
"updatedAt": "2020-05-21T07:30:10.417Z"
}
]
}
]
}
As you can see in the courseAvailable it returned 3 elements, And I wanted to do the distinction by distinct the element if the (section,start,end) are the same
so this is my expected output
{
"success": true,
"data": [
{
"id": 132,
"courseID": "CSS112",
"courseName": "COMPUTER PROGRAMMING",
"required": null,
"createdAt": "2020-05-21T07:29:58.596Z",
"updatedAt": "2020-05-21T07:29:58.596Z",
"courseAvailable": [
{
"id": 508,
"courseID": "CSS112",
"semester": 2,
"credit": 3,
"totalSeat": 55,
"section": "1",
"allowedGroup": "CSS 1 A(0)",
"day": "อ.",
"start": "08.30",
"end": "10.30",
"classroom": "SCL607",
"createdAt": "2020-05-21T07:30:10.417Z",
"updatedAt": "2020-05-21T07:30:10.417Z"
},
{
"id": 510,
"courseID": "CSS112",
"semester": 2,
"credit": 3,
"totalSeat": 55,
"section": "1",
"allowedGroup": "OTHER (0)",
"day": "อ.",
"start": "10.30",
"end": "12.30",
"classroom": "SCL703",
"createdAt": "2020-05-21T07:30:10.417Z",
"updatedAt": "2020-05-21T07:30:10.417Z"
}
]
}
]
}
(MY EXPECTATION) You can see that the id 509 is disappeared because the (section,start,end) have been queried by the distinct
What I've tried
const courses = await Course.findAll({
subQuery: false,
order: [ [ 'courseID', 'ASC' ] ],
include: [
{
model: CourseAvailable,
as: 'courseAvailable',
attributes: [ [ sequelize.fn('DISTINCT', sequelize.col('section')), 'section' ] ].concat(
Object.keys(CourseAvailable.rawAttributes)
), // was trying to do distinct only one column for checking if the distinct working or not working at all, and I am not sure if this is the right way to do it also, after I've been researching it for a day but found nothings that will solves my problem
required: false
}
]
});
But it threw me an error => syntax error at or near \"DISTINCT\".
I also tried using sequelize.literal to do the distinct as well but the error still the same
I am posting the following Order to the shopify api Order endpoint. The Order shows up in the shop and everything works as it should, except that the stock quantity of the variants in orders placed via the API are not decreased automatically by shopify. When I place an order within the admin console, they are decreased automatically. Shopify inventory tracking is turned on for the products. Any ideas would be greatly appreciated.
{
"order": {
"email": "someName#yahoo.com",
"financial_status": "paid",
"fulfillment_status": null,
"send_receipt": true,
"send_fulfillment_receipt": true,
"note": "Created by someName",
"line_items": [
{
"variant_id": 21718275463,
"quantity": 1,
"price": 99,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717700871,
"quantity": 1,
"price": 1000,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717690055,
"quantity": 1,
"price": 555,
"requires_shipping": true,
"product_id": 6821668807
}
],
"processing_method": "offsite",
"shipping_address": {
"first_name": "Chris",
"address1": "111 Love Road",
"phone": "9999999999",
"city": "St. Louis",
"zip": "63123",
"province": "MO",
"country": "United States",
"last_name": "Becker",
"name": "Chris Becker",
"country_code": "US",
"province_code": "MO"
},
"source_name": "someName",
"taxes_included": false,
"shipping_lines": [
{
"title": "standard",
"price": 0.00,
"code": null,
"source": "brand owner on shopify",
"carrier_identifier": null,
"tax_lines": null
}
],
"tags": "someName"
}
}
{
"variant": {
"id": 21718275463,
"product_id": 6820646151,
"title": "m / red",
"price": "99.00",
"sku": "",
"position": 2,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "900.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "m",
"option2": "red",
"option3": null,
"created_at": "2016-05-27T13:16:26-04:00",
"updated_at": "2016-05-28T13:28:20-04:00",
"taxable": false,
"barcode": "",
"image_id": 13217378823,
"inventory_quantity": 1,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 1,
"requires_shipping": true
}
}
{
"variant": {
"id": 21717700871,
"product_id": 6820646151,
"title": "s / green",
"price": "1000.00",
"sku": "",
"position": 1,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "1111.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "s",
"option2": "green",
"option3": null,
"created_at": "2016-05-27T13:05:56-04:00",
"updated_at": "2016-05-28T12:17:22-04:00",
"taxable": true,
"barcode": "",
"image_id": 13160712135,
"inventory_quantity": 2,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 2,
"requires_shipping": true
}
}
{
"variant": {
"id": 21717690055,
"product_id": 6821668807,
"title": "Default Title",
"price": "555.00",
"sku": "",
"position": 1,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "666.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Default Title",
"option2": null,
"option3": null,
"created_at": "2016-05-27T13:05:39-04:00",
"updated_at": "2016-05-28T12:17:22-04:00",
"taxable": true,
"barcode": "",
"image_id": null,
"inventory_quantity": 2,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 2,
"requires_shipping": true
}
}
You created a fake order using the API. Fake orders like that don't transact money or trigger the usual internal checks and balances without some extra effort. Maybe if you tried adding a fulfillment to the order, Shopify might ding inventory levels? Seems like something to try anyway.
I have a problem. When I try to make test my json, it says that it is not valid. But when I test it with online services, it reads it well.
The code I use to test if json is valid is:
NSString* stringRes = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[NSJSONSerialization isValidJSONObject:stringRes];
Where stringRes is son string in NSString format.(From data response)
JSON :
{
"response": [
9,
{
"id": 47,
"from_id": 211551056,
"to_id": -101815039,
"date": 1442585775,
"post_type": "post",
"text": "Кто на андроид кодит хоть немножк ? Хотя бы hello world ?",
"can_edit": 1,
"created_by": 211551056,
"can_delete": 1,
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 0,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
},
{
"id": 43,
"from_id": 217702824,
"to_id": -101815039,
"date": 1442555658,
"post_type": "post",
"text": "Учебник по географии",
"can_delete": 1,
"attachment": {
"type": "doc",
"doc": {
"did": 419802605,
"owner_id": 217702824,
"title": "11_geo_m_2012.pdf",
"size": 92318316,
"ext": "pdf",
"url": "http://vk.com/doc217702824_419802605?hash=5eb9bb9753a6f88e88&dl=fcadca27db5845a002&api=1",
"access_key": "8e4218746055687cc2"
}
},
"attachments": [
{
"type": "doc",
"doc": {
"did": 419802605,
"owner_id": 217702824,
"title": "11_geo_m_2012.pdf",
"size": 92318316,
"ext": "pdf",
"url": "http://vk.com/doc217702824_419802605?hash=5eb9bb9753a6f88e88&dl=fcadca27db5845a002&api=1",
"access_key": "8e4218746055687cc2"
}
}
],
"post_source": {
"type": "api",
"platform": "android"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 3,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 0,
"reply_count": 0
},
{
"id": 37,
"from_id": 211551056,
"to_id": -101815039,
"date": 1442502437,
"post_type": "post",
"text": "У кого айфон, + в комменты",
"can_delete": 1,
"attachment": {
"type": "poll",
"poll": {
"poll_id": 195892301,
"question": "Удобно смотреть расписание ?(На сайте)"
}
},
"attachments": [
{
"type": "poll",
"poll": {
"poll_id": 195892301,
"question": "Удобно смотреть расписание ?(На сайте)"
}
}
],
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 5,
"can_post": 1
},
"likes": {
"count": 0,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 5
},
{
"id": 36,
"from_id": 249011483,
"to_id": -101815039,
"date": 1442500757,
"post_type": "post",
"text": "Домашку выложить не забудьте 👌👆",
"can_delete": 1,
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 1,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
},
{
"id": 28,
"from_id": 211551056,
"to_id": -101815039,
"date": 1442306249,
"post_type": "post",
"text": "",
"can_delete": 1,
"media": {
"type": "photo",
"owner_id": -101815039,
"item_id": 381477357,
"thumb_src": "http://cs624425.vk.me/v624425056/49e35/_w_YDirrrQU.jpg"
},
"attachment": {
"type": "photo",
"photo": {
"pid": 381477357,
"aid": -8,
"owner_id": -101815039,
"user_id": 211551056,
"src": "http://cs624425.vk.me/v624425056/49e35/_w_YDirrrQU.jpg",
"src_big": "http://cs624425.vk.me/v624425056/49e36/439edT8aXks.jpg",
"src_small": "http://cs624425.vk.me/v624425056/49e34/uLxZj9yF1F4.jpg",
"src_xbig": "http://cs624425.vk.me/v624425056/49e37/nhvaG43cV-Y.jpg",
"src_xxbig": "http://cs624425.vk.me/v624425056/49e38/Ox54xM039hg.jpg",
"width": 960,
"height": 720,
"text": "",
"created": 1442306250,
"lat": 55.785025,
"long": 37.706605,
"post_id": 28,
"access_key": "454823aa95a2ee9fbc"
}
},
"attachments": [
{
"type": "photo",
"photo": {
"pid": 381477357,
"aid": -8,
"owner_id": -101815039,
"user_id": 211551056,
"src": "http://cs624425.vk.me/v624425056/49e35/_w_YDirrrQU.jpg",
"src_big": "http://cs624425.vk.me/v624425056/49e36/439edT8aXks.jpg",
"src_small": "http://cs624425.vk.me/v624425056/49e34/uLxZj9yF1F4.jpg",
"src_xbig": "http://cs624425.vk.me/v624425056/49e37/nhvaG43cV-Y.jpg",
"src_xxbig": "http://cs624425.vk.me/v624425056/49e38/Ox54xM039hg.jpg",
"width": 960,
"height": 720,
"text": "",
"created": 1442306250,
"lat": 55.785025,
"long": 37.706605,
"post_id": 28,
"access_key": "454823aa95a2ee9fbc"
}
}
],
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 1,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
},
{
"id": 27,
"from_id": 211551056,
"to_id": -101815039,
"date": 1442306164,
"post_type": "post",
"text": "",
"can_delete": 1,
"media": {
"type": "photo",
"owner_id": -101815039,
"item_id": 381477244,
"thumb_src": "http://cs624425.vk.me/v624425056/49e2c/kttj5pUpjTk.jpg"
},
"attachment": {
"type": "photo",
"photo": {
"pid": 381477244,
"aid": -8,
"owner_id": -101815039,
"user_id": 211551056,
"src": "http://cs624425.vk.me/v624425056/49e2c/kttj5pUpjTk.jpg",
"src_big": "http://cs624425.vk.me/v624425056/49e2d/ihg9szTvLew.jpg",
"src_small": "http://cs624425.vk.me/v624425056/49e2b/GpS0xwCa66c.jpg",
"src_xbig": "http://cs624425.vk.me/v624425056/49e2e/pe4tflJokqs.jpg",
"src_xxbig": "http://cs624425.vk.me/v624425056/49e2f/7vkU8nUyNxc.jpg",
"width": 960,
"height": 720,
"text": "",
"created": 1442306166,
"lat": 55.785083,
"long": 37.711116,
"post_id": 27,
"access_key": "cb01ac011f4abbc0af"
}
},
"attachments": [
{
"type": "photo",
"photo": {
"pid": 381477244,
"aid": -8,
"owner_id": -101815039,
"user_id": 211551056,
"src": "http://cs624425.vk.me/v624425056/49e2c/kttj5pUpjTk.jpg",
"src_big": "http://cs624425.vk.me/v624425056/49e2d/ihg9szTvLew.jpg",
"src_small": "http://cs624425.vk.me/v624425056/49e2b/GpS0xwCa66c.jpg",
"src_xbig": "http://cs624425.vk.me/v624425056/49e2e/pe4tflJokqs.jpg",
"src_xxbig": "http://cs624425.vk.me/v624425056/49e2f/7vkU8nUyNxc.jpg",
"width": 960,
"height": 720,
"text": "",
"created": 1442306166,
"lat": 55.785083,
"long": 37.711116,
"post_id": 27,
"access_key": "cb01ac011f4abbc0af"
}
}
],
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 1,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
},
{
"id": 16,
"from_id": 249011483,
"to_id": -101815039,
"date": 1442069345,
"post_type": "post",
"text": "Кто нибудь сделал алгебру ?",
"can_delete": 1,
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 6,
"can_post": 1
},
"likes": {
"count": 3,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 6
},
{
"id": 9,
"from_id": 127082413,
"to_id": -101815039,
"date": 1441911418,
"post_type": "post",
"text": "Официальная информациия ,староста нашей группы Александр Кондор!",
"can_delete": 1,
"post_source": {
"type": "api",
"platform": "android"
},
"comments": {
"count": 6,
"can_post": 1
},
"likes": {
"count": 2,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 6
},
{
"id": 1,
"from_id": -101815039,
"to_id": -101815039,
"date": 1441656588,
"post_type": "post",
"text": "",
"can_delete": 1,
"can_pin": 1,
"media": {
"type": "photo",
"owner_id": -101815039,
"item_id": 380592775,
"thumb_src": "http://cs629111.vk.me/v629111548/e99f/DcV1yHZK1fw.jpg"
},
"attachment": {
"type": "photo",
"photo": {
"pid": 380592775,
"aid": -6,
"owner_id": -101815039,
"user_id": 100,
"src": "http://cs629111.vk.me/v629111548/e99f/DcV1yHZK1fw.jpg",
"src_big": "http://cs629111.vk.me/v629111548/e9a0/Qf8q8PpH7Jg.jpg",
"src_small": "http://cs629111.vk.me/v629111548/e99e/2Jq8e-0SptQ.jpg",
"src_xbig": "http://cs629111.vk.me/v629111548/e9a1/Uha0MvOoVCU.jpg",
"src_xxbig": "http://cs629111.vk.me/v629111548/e9a2/v8hqUldA6Kk.jpg",
"width": 730,
"height": 1024,
"text": "",
"created": 1441656588,
"post_id": 1
}
},
"attachments": [
{
"type": "photo",
"photo": {
"pid": 380592775,
"aid": -6,
"owner_id": -101815039,
"user_id": 100,
"src": "http://cs629111.vk.me/v629111548/e99f/DcV1yHZK1fw.jpg",
"src_big": "http://cs629111.vk.me/v629111548/e9a0/Qf8q8PpH7Jg.jpg",
"src_small": "http://cs629111.vk.me/v629111548/e99e/2Jq8e-0SptQ.jpg",
"src_xbig": "http://cs629111.vk.me/v629111548/e9a1/Uha0MvOoVCU.jpg",
"src_xxbig": "http://cs629111.vk.me/v629111548/e9a2/v8hqUldA6Kk.jpg",
"width": 730,
"height": 1024,
"text": "",
"created": 1441656588,
"post_id": 1
}
}
],
"post_source": {
"type": "api",
"platform": "android",
"data": "profile_photo"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 0,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
}
]
}
UPD: Solved by using
NSData* data = [stringRes dataUsingEncoding:NSUTF8StringEncoding];
isValidJSONObject tests if a JSON object (a NSDictionary or NSArray) can be successfully converted to JSON data.
It is not for testing if an NSData object contains valid JSON data. To test for valid JSON data you just call
[NSJSONSerialization JSONObjectWithData:data ...]
and check if the return value is nil or not.