Example of using operator for filter in dataweave 2 - mule

I am using dataweave 2 for transformation. I need to use filter operator to filter payload depending upon the value in the request body. The reason for using 'using' is because the value is optional and in that scenario I do not want to filter the payload. My transformation -
%dw 2.0
output application/json skipNullOn="everywhere"
fun toDate(v) = (v as String{format:'yyyy-MM-dd'} as Date) default null
---
if (payload is Array)
flatten (
payload **//need to put 2 filters here on $.CloudAccountDetail.status and $.CloudAccountDetail.clouAccountId //** map (item, order) -> (
flatten ( [
item.NamedSubscriptions map {
key: $.SubscriptionId,
expiryDate: toDate($.ExpiryDate)
//nextPaymentDate: toDate($.NextPaymentDueDate)
}
,
item.UnnamedSubscriptions map {
key: $.SubscriptionId,
expiryDate: toDate($.ExpiryDate),
cloudPublicName: item.CloudAccountDetail.CloudAccountPublicName,
cloudAccountId: $.EskoCloudAccount
}
] )
)
)
else []
Input -
[
{
"CloudAccountDetail": {
"CompanyCode": "B_B001",
"CloudAccountId": "a-t-1000-5001-0687-0024",
"CloudAccountPublicName": "dodp-testcloud",
"Status": "SUBSCRIBED",
"ClusterName": "ci.dev.cloudi.city"
},
"NamedSubscriptions": [
{
"SubscriptionId": "8f724cc9-bb21-43bc-8911-94d267eb7917",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:19.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": "eskododp03#yahoo.be",
"AssignedBy": "LicenseService",
"AssignedDate": "2020-01-07T11:16:52.723",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "5c06112a-90a4-4e76-b2f4-bd19a1ce92b3",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:19.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "a258a7fc-cff6-4b53-b19d-4e25a8dbcee6",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:19.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "e30f16af-de60-4b84-bdae-aa7b6523c316",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:19.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "5ee9eeb6-9d65-42b8-b594-68c9528ff25b",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:20.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "818b38f1-0a10-45dc-ae16-f7d804b31cbc",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:20.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "cf5fc421-8ee0-4f1f-a1ca-e64daef2e0c6",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:20.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
}
],
"UnnamedSubscriptions": [
{
"SubscriptionId": "c56c5d21-83dd-4df5-851c-52fd5686240b",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:02.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "1d5bf54c-e812-4c17-830d-d3a1104d66a5",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:02.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "fbe0bbef-3cc2-451a-9866-0bb31a829850",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:02.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "368fa144-5a94-4ead-ba69-502ca6419de4",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:02.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "3404fb6e-d234-4dac-a5a1-96c7534ccf21",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:03.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "71d88ad6-3108-499e-8be9-3638c7298770",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:03.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "992b551e-1499-4971-bc9b-34075820faa7",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:03.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
}
],
"StorageSubscriptions": [
{
"EntitlementId": "5ceae026-5c3e-40df-a9f8-2de4f4570566",
"OrderNumber": "TEST708259",
"StorageInGb": 50,
"ExpiryDate": "2021-01-07T00:00:00",
"StartDate": "2020-01-07T12:37:12.697",
"CanceledDate": null,
"ProductCode": "ECL-ECL-ST-ST50",
"ProductName": "Storage Tier 1 (50GB)",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
}
],
"TransactionSubscriptions": [
{
"EntitlementId": "6eaf4b93-8fef-4423-88fd-7e83d790f6f7",
"OrderNumber": "TEST708259",
"NumberOfTransactions": 12000,
"ExpiryDate": "2021-01-07T00:00:00",
"StartDate": "2020-01-07T12:17:56.257",
"CanceledDate": null,
"ProductCode": "ECL-ECL-BTR-BTR1000",
"ProductName": "Basic Transactions Tier 2 (1000/m)",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
}
]
},
{
"CloudAccountDetail": {
"CompanyCode": "B_B001",
"CloudAccountId": "a-t-1001-0001-0039-0024",
"CloudAccountPublicName": "Test-Tom-Desmet",
"Status": "TRIAL",
"ClusterName": "ci.dev.cloudi.city"
},
"NamedSubscriptions": [
{
"SubscriptionId": "3dc289af-d469-4dba-875e-354c75d2a31a",
"OrderNumber": "TEST709894",
"StartDate": "2020-06-30T14:21:34.773",
"ExpiryDate": "2021-07-09T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": "eskododp03#yahoo.be",
"AssignedBy": "LicenseService",
"AssignedDate": "2020-06-30T13:31:01.777",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "3e6818fb-1c4f-4046-9783-5b76d3050eec",
"OrderNumber": "TEST709894",
"StartDate": "2020-06-30T14:21:35.773",
"ExpiryDate": "2021-07-09T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
}
],
"UnnamedSubscriptions": [
{
"SubscriptionId": "baf3d5c7-b53e-460e-93a5-311b95924fca",
"OrderNumber": "TEST709894",
"StartDate": "2020-06-30T15:18:15.593",
"ExpiryDate": "2021-07-09T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "69071fd1-59b5-44ef-a594-95141d68ef4c",
"OrderNumber": "TEST709894",
"StartDate": "2020-06-30T15:18:16.593",
"ExpiryDate": "2021-07-09T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
}
],
"StorageSubscriptions": [
{
"EntitlementId": "f6f444e3-4dea-43d9-afc0-19d24200cf46",
"OrderNumber": "TEST709894",
"StorageInGb": 50,
"ExpiryDate": "2021-06-30T00:00:00",
"StartDate": "2020-06-30T14:57:54.05",
"CanceledDate": null,
"ProductCode": "ECL-ECL-ST-ST50",
"ProductName": "Storage Tier 1 (50GB)",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
}
],
"TransactionSubscriptions": [
{
"EntitlementId": "22d25390-4183-4c89-8461-38ebf048812f",
"OrderNumber": "TEST709894",
"NumberOfTransactions": 12000,
"ExpiryDate": "2021-06-30T00:00:00",
"StartDate": "2020-06-30T14:24:10.017",
"CanceledDate": null,
"ProductCode": "ECL-ECL-BTR-BTR1000",
"ProductName": "Basic Transactions Tier 2 (1000/m)",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
}
]
}
]
Output I need after transformation. Just take note I have not considered filtering in the ouput. -
[
{
"key": "8f724cc9-bb21-43bc-8911-94d267eb7917",
"expiryDate": "2021-01-16"
},
{
"key": "5c06112a-90a4-4e76-b2f4-bd19a1ce92b3",
"expiryDate": "2021-01-16"
},
{
"key": "a258a7fc-cff6-4b53-b19d-4e25a8dbcee6",
"expiryDate": "2021-01-16"
},
{
"key": "e30f16af-de60-4b84-bdae-aa7b6523c316",
"expiryDate": "2021-01-16"
},
{
"key": "5ee9eeb6-9d65-42b8-b594-68c9528ff25b",
"expiryDate": "2021-01-16"
},
{
"key": "818b38f1-0a10-45dc-ae16-f7d804b31cbc",
"expiryDate": "2021-01-16"
},
{
"key": "cf5fc421-8ee0-4f1f-a1ca-e64daef2e0c6",
"expiryDate": "2021-01-16"
},
{
"key": "c56c5d21-83dd-4df5-851c-52fd5686240b",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "1d5bf54c-e812-4c17-830d-d3a1104d66a5",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "fbe0bbef-3cc2-451a-9866-0bb31a829850",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "368fa144-5a94-4ead-ba69-502ca6419de4",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "3404fb6e-d234-4dac-a5a1-96c7534ccf21",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "71d88ad6-3108-499e-8be9-3638c7298770",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "992b551e-1499-4971-bc9b-34075820faa7",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "3dc289af-d469-4dba-875e-354c75d2a31a",
"expiryDate": "2021-07-09"
},
{
"key": "3e6818fb-1c4f-4046-9783-5b76d3050eec",
"expiryDate": "2021-07-09"
},
{
"key": "baf3d5c7-b53e-460e-93a5-311b95924fca",
"expiryDate": "2021-07-09",
"cloudPublicName": "Test-Tom-Desmet",
"cloudAccountId": "a-t-1001-0001-0039-0024"
},
{
"key": "69071fd1-59b5-44ef-a594-95141d68ef4c",
"expiryDate": "2021-07-09",
"cloudPublicName": "Test-Tom-Desmet",
"cloudAccountId": "a-t-1001-0001-0039-0024"
}
]

You should first apply the filter on the whole array, and then do the rest of the transformation:
%dw 2.0
output application/json skipNullOn="everywhere"
fun toDate(v) = (v as String{format:'yyyy-MM-dd'} as Date) default null
var status = 'SUBSCRIBED'
var accountId = 'a-t-1000-5001-0687-0024'
---
if (payload is Array)
flatten(payload filter ($.CloudAccountDetail.CloudAccountId == accountId and $.CloudAccountDetail.Status == status) map(item, value) ->
flatten ( [
item.NamedSubscriptions map {
key: $.SubscriptionId,
expiryDate: toDate($.ExpiryDate)
//nextPaymentDate: toDate($.NextPaymentDueDate)
}
,
item.UnnamedSubscriptions map {
key: $.SubscriptionId,
expiryDate: toDate($.ExpiryDate),
cloudPublicName: item.CloudAccountDetail.CloudAccountPublicName,
cloudAccountId: $.EskoCloudAccount
}
] ))
else []
The above dataweave expression applied to the provided input results in:
[
{
"key": "8f724cc9-bb21-43bc-8911-94d267eb7917",
"expiryDate": "2021-01-16"
},
{
"key": "5c06112a-90a4-4e76-b2f4-bd19a1ce92b3",
"expiryDate": "2021-01-16"
},
{
"key": "a258a7fc-cff6-4b53-b19d-4e25a8dbcee6",
"expiryDate": "2021-01-16"
},
{
"key": "e30f16af-de60-4b84-bdae-aa7b6523c316",
"expiryDate": "2021-01-16"
},
{
"key": "5ee9eeb6-9d65-42b8-b594-68c9528ff25b",
"expiryDate": "2021-01-16"
},
{
"key": "818b38f1-0a10-45dc-ae16-f7d804b31cbc",
"expiryDate": "2021-01-16"
},
{
"key": "cf5fc421-8ee0-4f1f-a1ca-e64daef2e0c6",
"expiryDate": "2021-01-16"
},
{
"key": "c56c5d21-83dd-4df5-851c-52fd5686240b",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "1d5bf54c-e812-4c17-830d-d3a1104d66a5",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "fbe0bbef-3cc2-451a-9866-0bb31a829850",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "368fa144-5a94-4ead-ba69-502ca6419de4",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "3404fb6e-d234-4dac-a5a1-96c7534ccf21",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "71d88ad6-3108-499e-8be9-3638c7298770",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "992b551e-1499-4971-bc9b-34075820faa7",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
}
]

Much cleaner example. Instead of using flatten, try using a function to populate the values.
Example:
%dw 2.0
var accountStatus=["SUBSCRIBED"]
var accountId=["a-t-1000-5001-0687-0024"]
fun getData(items, account, isUnnamedSubscriptions) =
(items default []) map {
"key": $.SubscriptionId,
"expiryDate": $.ExpiryDate as Date,
("cloudPublicName": account.CloudAccountPublicName) if (isUnnamedSubscriptions),
("cloudAccountId": account.CloudAccountId) if (isUnnamedSubscriptions)
}
output application/json
---
(payload[?((accountId contains $.CloudAccountDetail.CloudAccountId)
and (accountStatus contains $.CloudAccountDetail.Status) )] map (
getData($.NamedSubscriptions, $.CloudAccountDetail, false)
++
getData($.UnnamedSubscriptions, $.CloudAccountDetail, true)
) flatMap () -> $) default []
accountId variable is an Array and you can replace that as a string as well and similar to status in line 2 and line 3.
If you have multiple accountId to filter, just add another string in the accountId, same as the status.
If you want to exclude filter if the CloudAccountDetail.Status is Null and CloudAccountDetail.CloudAccountId is Null
You can create a function to return boolean. the funciton should be like this
fun isValidFilter(id, stat) =
if ( id !=null and stat != null)
((accountId contains id) and (accountStatus contains stat))
else (true)
and the pass the value to the function isValidFilter
Example:
payload[?( (isValidFilter($.CloudAccountDetail.CloudAccountId,
$.CloudAccountDetail.Status)) )] map ...

Related

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

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

Not Showing nested Json Data from Custom Api in FlatList in ReactNative

i tried several times to fetch data, but it is not showing anything in the app,
here is the code base for the fetching Api data.
it is console logging.
the data is console logging in the metro
but while trying to render in the flat List it is not showing anything,instead a blank page is displayed.
the data is a nested objects.
import React, {useEffect, useState} from 'react';
import {FlatList, SafeAreaView, Text, View} from 'react-native';
export default FoodProductsApi = () => {
const [data, setData] = useState([]);
const getFoodApi = () => {
fetch(
'url',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
countryName: 'India',
deliveryPincode: '5600100',
categoryType: 'Food',
}),
},
)
.then(response => response.json())
.then(json => {
setData(json.foodProducts);
console.log(json.foodProducts.categories);
})
.catch(error => {
console.error(error);
});
};
useEffect(() => {
getFoodApi();
}, []);
const keyExtractor = () => item => item.id;
return (
<SafeAreaView>
<Text>Name</Text>
<FlatList
data={data.foodProducts}
keyExtractor={keyExtractor}
renderItem={index => (
<View style={{flex: 1}}>
{index.data.foodProducts.map((i, v) => {
<Text>{i.categoryName}</Text>;
})}
</View>
)}
/>
</SafeAreaView>
);
};
this is the json Data
{
"responseCode": "200",
"responseMessage": "Successfull",
"foodProducts": {
"hubId": "610299e303be56ca3924971e",
"categories": [
{
"id": "61028aff294f460012c9101e",
"categoryName": "Kalyani Biryani",
"rankOrder": 6,
"status": "ACTIVE",
"createDate": "2021-07-29T11:03:27.345+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:17:55.270+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019627",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6f03be56ca3924b8f9",
"zohoItemId": "594850000000022886",
"productName": "Kalyani Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B035",
"mrp": 500,
"discountedPrice": 400,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.059+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.059+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "58.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b900",
"zohoItemId": "594850000000022946",
"productName": "Kalyani Egg Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B037",
"mrp": 300,
"discountedPrice": 290,
"rankOrder": 6,
"description": null,
"hsnCode": "5006097",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.348+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.348+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "56.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b907",
"zohoItemId": "594850000000022915",
"productName": "Kalyani Mutton Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B036",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.652+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.652+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Mutton",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "52.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b910",
"zohoItemId": "594850000000022977",
"productName": "Kalyani Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Veg",
"sku": "B038",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 12,
"description": null,
"hsnCode": "5006978",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.938+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.938+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "1",
"categoryType": "Food",
"availableStock": "51.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7603be56ca3924b992",
"zohoItemId": "594850000000022762",
"productName": "Thalassery Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B031",
"mrp": 400,
"discountedPrice": 320,
"rankOrder": 17,
"description": null,
"hsnCode": "5006990",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:18.173+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:18.173+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "128.000000",
"isFavorite": null,
"hubId": null
}
]
},
{
"id": "61028aa8294f460012c9101b",
"categoryName": "Bombay Biryani",
"rankOrder": 23,
"status": "ACTIVE",
"createDate": "2021-07-29T11:02:00.541+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:18:27.081+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019605",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6803be56ca3924b846",
"zohoItemId": "594850000000022576",
"productName": "Bombay Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Veg",
"sku": "B024",
"mrp": 400,
"discountedPrice": 360,
"rankOrder": 10,
"description": null,
"hsnCode": "50090994",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:03.459+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:03.459+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "130.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6703be56ca3924b832",
"zohoItemId": "594850000000022607",
"productName": "Bomaby Fish Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B025",
"mrp": 250,
"discountedPrice": 170,
"rankOrder": 11,
"description": null,
"hsnCode": "50090995",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.305+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.305+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Sea Food",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "145.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6803be56ca3924b83d",
"zohoItemId": "594850000000022638",
"productName": "Bombay Egg Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B026",
"mrp": 240,
"discountedPrice": 210,
"rankOrder": 16,
"description": null,
"hsnCode": "5009099",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.885+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.885+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "-141.000000",
"isFavorite": null,
"hubId": null
}
]
},
Hope this Solves your Problem,
import React from 'react';
import {
SafeAreaView,
StyleSheet,
View,
Text,
FlatList
} from 'react-native';
const App = () => {
const [data, setData] = useState([]);
useEffect(() => {
getFoodApi();
}, []);
function getFoodApi()
{
setData({
"foodProducts": {
"hubId": "610299e303be56ca3924971e",
"categories": [
{
"id": "61028aff294f460012c9101e",
"categoryName": "Kalyani Biryani",
"rankOrder": 6,
"status": "ACTIVE",
"createDate": "2021-07-29T11:03:27.345+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:17:55.270+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019627",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6f03be56ca3924b8f9",
"zohoItemId": "594850000000022886",
"productName": "Kalyani Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B035",
"mrp": 500,
"discountedPrice": 400,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.059+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.059+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "58.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b900",
"zohoItemId": "594850000000022946",
"productName": "Kalyani Egg Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B037",
"mrp": 300,
"discountedPrice": 290,
"rankOrder": 6,
"description": null,
"hsnCode": "5006097",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.348+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.348+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "56.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b907",
"zohoItemId": "594850000000022915",
"productName": "Kalyani Mutton Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B036",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.652+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.652+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Mutton",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "52.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b910",
"zohoItemId": "594850000000022977",
"productName": "Kalyani Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Veg",
"sku": "B038",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 12,
"description": null,
"hsnCode": "5006978",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.938+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.938+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "1",
"categoryType": "Food",
"availableStock": "51.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7603be56ca3924b992",
"zohoItemId": "594850000000022762",
"productName": "Thalassery Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B031",
"mrp": 400,
"discountedPrice": 320,
"rankOrder": 17,
"description": null,
"hsnCode": "5006990",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:18.173+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:18.173+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "128.000000",
"isFavorite": null,
"hubId": null
}
]//food products[0]
}, //categories[0]
{
"id": "61028aa8294f460012c9101b",
"categoryName": "Bombay Biryani",
"rankOrder": 23,
"status": "ACTIVE",
"createDate": "2021-07-29T11:02:00.541+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:18:27.081+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019605",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6803be56ca3924b846",
"zohoItemId": "594850000000022576",
"productName": "Bombay Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Veg",
"sku": "B024",
"mrp": 400,
"discountedPrice": 360,
"rankOrder": 10,
"description": null,
"hsnCode": "50090994",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:03.459+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:03.459+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "130.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6703be56ca3924b832",
"zohoItemId": "594850000000022607",
"productName": "Bomaby Fish Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B025",
"mrp": 250,
"discountedPrice": 170,
"rankOrder": 11,
"description": null,
"hsnCode": "50090995",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.305+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.305+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Sea Food",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "145.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6803be56ca3924b83d",
"zohoItemId": "594850000000022638",
"productName": "Bombay Egg Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B026",
"mrp": 240,
"discountedPrice": 210,
"rankOrder": 16,
"description": null,
"hsnCode": "5009099",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.885+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.885+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "-141.000000",
"isFavorite": null,
"hubId": null
}
]
}
]//categories
}//foodApi
})
}
return (
<SafeAreaView style={{flex:1}}>
<Text>Name</Text>
<FlatList
style={{flex:1}}
data={data.foodProducts.categories}
keyExtractor={(item,index)=>index.toString()}
renderItem={({ item, index }) => {
return (
<View style={{flex: 1}}>
<Text> categoreyname {item.categoryName}</Text>
{item.foodProducts.map(ele => {
return (
<Text style={{ paddingLeft: 5 }}> productName { ele.productName}</Text>
)
})}
</View>
)
}}
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
});
export default App;
Flatlist will loop only array of object . in your code you have tried to loop objects (data.foodProducts).
Replace data={data.foodProducts} to data={data.foodproducts.categories}. Now it will loop, because its an array of objects.
Array of objects will be similar to this [{name:"React",age:5}]. This will be looped by flatlist
Objects will be similar to this {name:"react",age:5}. This will not looped by flatlist.
You can check whether data is an array or object using console.log(typeof data.foodproducts).

out of 17 Task work items 15 are coming and 2 Task are not migrate

I have used the version of 10.2 and facing one of the issue following
Issue is that out of 17 Task work items 15 are coming and 2 Task are not migrated but in that place two Product backlog item created with no title and state is coming with new state
Here is my config file:
{ "Version": "10.2",
"TelemetryEnableTrace": false,
"workaroundForQuerySOAPBugEnabled": false,
"ChangeSetMappingFile": null,
"Source": {
"Collection": "",
"Project": "Road To NPD 3.0",
"ReflectedWorkItemIDFieldName": "PATTInitiativesRefID",
"AllowCrossProjectLinking": false,
"PersonalAccessToken": "",
"LanguageMaps": {
"AreaPath": "Road To NPD 3.0",
"IterationPath": "Road To NPD 3.0"
} }, "Target": {
"Collection": "",
"Project": "AS-Scrum-RoadToNPD3.0",
"ReflectedWorkItemIDFieldName": "AutoSolScrumRefID",
"AllowCrossProjectLinking": false,
"PersonalAccessToken": "",
"LanguageMaps": {
"AreaPath": "AS-Scrum-RoadToNPD3.0",
"IterationPath": "AS-Scrum-RoadToNPD3.0" } }, "FieldMaps": [
{
"ObjectType": "MultiValueConditionalMapConfig",
"WorkItemTypeName": "*",
"sourceFieldsAndValues": {
"Field1": "Value1",
"Field2": "Value2"
},
"targetFieldsAndValues": {
"Field1": "Value1",
"Field2": "Value2"
}
},
{
"ObjectType": "FieldBlankMapConfig",
"WorkItemTypeName": "*",
"targetField": "TfsMigrationTool.ReflectedWorkItemId"
},
{
"ObjectType": "FieldValueMapConfig",
"WorkItemTypeName": "*",
"sourceField": "System.State",
"targetField": "System.State",
"defaultValue": "New",
//"valueMapping": {
// "Approved": "New",
//"New": "New",
//"Committed": "Active",
//"In Progress": "Active",
//"To Do": "New",
//"Done": "Closed",
//"Removed": "Removed"
//}
},
{
"ObjectType": "FieldtoFieldMapConfig",
"WorkItemTypeName": "*",
"sourceField": "Microsoft.VSTS.Common.BacklogPriority",
"targetField": "Microsoft.VSTS.Common.StackRank",
"defaultValue": null
},
{
"ObjectType": "FieldtoFieldMultiMapConfig",
"WorkItemTypeName": "*",
"SourceToTargetMappings": {
"SourceField1": "TargetField1",
"SourceField2": "TargetField2"
}
},
{
"ObjectType": "FieldtoTagMapConfig",
"WorkItemTypeName": "*",
"sourceField": "System.State",
"formatExpression": "ScrumState:{0}"
},
{
"ObjectType": "FieldMergeMapConfig",
"WorkItemTypeName": "*",
"sourceField1": "System.Description",
"sourceField2": "Microsoft.VSTS.Common.AcceptanceCriteria",
"targetField": "System.Description",
"formatExpression": "{0} <br/><br/><h3>Acceptance Criteria</h3>{1}",
"doneMatch": "##DONE##"
},
{
"ObjectType": "RegexFieldMapConfig",
"WorkItemTypeName": "*",
"sourceField": "COMPANY.PRODUCT.Release",
"targetField": "COMPANY.DEVISION.MinorReleaseVersion",
"pattern": "PRODUCT \\d{4}.(\\d{1})",
"replacement": "$1"
},
{
"ObjectType": "FieldValuetoTagMapConfig",
"WorkItemTypeName": "*",
"sourceField": "Microsoft.VSTS.CMMI.Blocked",
"pattern": "Yes",
"formatExpression": "{0}"
},
{
"ObjectType": "TreeToTagMapConfig",
"WorkItemTypeName": "*",
"toSkip": 3,
"timeTravel": 1
} ], "WorkItemTypeDefinition": {
"Product Backlog Item": "Product Backlog Item", "Epic": "Epic", "Task": "Task" }, "GitRepoMapping": null, "Processors": [
{
"ObjectType": "NodeStructuresMigrationConfig",
"PrefixProjectToNodes": false,
"Enabled": false,
"BasePaths": [
"Product\\Area\\Path1",
"Product\\Area\\Path2"
]
},
{
"ObjectType": "WorkItemMigrationConfig",
"ReplayRevisions": true,
"PrefixProjectToNodes": false,
"UpdateCreatedDate": true,
"UpdateCreatedBy": true,
"BuildFieldTable": false,
"AppendMigrationToolSignatureFooter": false,
"QueryBit": "AND [Microsoft.VSTS.Common.ClosedDate] != '' AND [System.WorkItemType] IN ('Task')",
"OrderBit": "[System.ChangedDate] desc",
"Enabled": true,
"LinkMigration": true,
"AttachmentMigration": true,
"AttachmentWorkingPath": "c:\\temp\\WorkItemAttachmentWorkingFolder\\",
"FixHtmlAttachmentLinks": false,
"SkipToFinalRevisedWorkItemType": false,
"WorkItemCreateRetryLimit": 5,
"FilterWorkItemsThatAlreadyExistInTarget": true,
"PauseAfterEachWorkItem": false,
"AttachmentMazSize": 480000000,
"CollapseRevisions": false,
"LinkMigrationSaveEachAsAdded": false
} ] }
This issue is due to some code malfunctioning that is responsible for changing the work item type which is not possible in the old Object Model. Some folks have had issues with it, and so there is SkipToFinalRevisedWorkItemType that can be added to look at the type of the last revision and use that rather than trying to mess around in between.
{
"ObjectType": "WorkItemMigrationConfig",
"ReplayRevisions": true,
"PrefixProjectToNodes": false,
"UpdateCreatedDate": true,
"UpdateCreatedBy": true,
"BuildFieldTable": false,
"AppendMigrationToolSignatureFooter": false,
"QueryBit": "AND [Microsoft.VSTS.Common.ClosedDate] != '' AND [System.WorkItemType] IN ('Task')",
"OrderBit": "[System.ChangedDate] desc",
"Enabled": true,
"LinkMigration": true,
"AttachmentMigration": true,
"AttachmentWorkingPath": "c:\\temp\\WorkItemAttachmentWorkingFolder\\",
"FixHtmlAttachmentLinks": false,
"SkipToFinalRevisedWorkItemType": true,
"WorkItemCreateRetryLimit": 5,
"FilterWorkItemsThatAlreadyExistInTarget": true,
"PauseAfterEachWorkItem": false,
"AttachmentMazSize": 480000000,
"CollapseRevisions": false,
"LinkMigrationSaveEachAsAdded": false
} ] }
Here I updated "SkipToFinalRevisedWorkItemType" to be true instead of false.

CosmosDB GeoSpatial Points Invalid

I'm using Azure's cosmos DB, and testing via the sqlquery in the Azure portal. Some points in my collection are valid, some are not. I am unable to tell from the GeoJSON spec if I am missing requirements. All my points pass the geojsonlint test: https://geojsonlint.com/
What could be causing invalid points? The locations are setup the same as far as I can tell.
My Query:
SELECT *
FROM events1 e
WHERE ST_ISVALID(e.location)
Running the query returns that these are valid:
[
{
"id": "b4b49b65-dfad-40f3-943b-753553507d2c",
"name": "OG Olympics",
"location": {
"type": "Point",
"coordinates": [
41.900697426935544,
12.480266913771628
]
},
"events": "Hockey",
"time": "00:00:00",
"recurring": null,
"date": null,
"difficulty": "Expert",
"ages": "Senior",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoHAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoHAAAAAAAAAA==/",
"_etag": "\"11003fb9-0000-0700-0000-5f2f15cf0000\"",
"_attachments": "attachments/",
"_ts": 1596921295
},
{
"id": "f2d063e3-5654-475d-8e97-7412dc77fcfb",
"name": "Test Event DenverCC",
"location": {
"type": "Point",
"coordinates": [
100.2093,
-15.868
]
},
"events": "Basketball",
"time": "18:00:00",
"recurring": null,
"date": null,
"difficulty": "Intermediate",
"ages": "Senior",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoJAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoJAAAAAAAAAA==/",
"_etag": "\"1300a79d-0000-0700-0000-5f304fc80000\"",
"_attachments": "attachments/",
"_ts": 1597001672
},
{
"id": "10000",
"name": "OG Olympics 2",
"location": {
"type": "Point",
"coordinates": [
41.000697426935545,
-12.080266913771627
]
},
"events": "Hockey",
"time": "00:00:00",
"recurring": null,
"date": null,
"difficulty": "Expert",
"ages": "Senior",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoKAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoKAAAAAAAAAA==/",
"_etag": "\"13003499-0000-0700-0000-5f304d580000\"",
"_attachments": "attachments/",
"_ts": 1597001048
}
]
But it returns that these are invalid:
{
"id": "1000",
"name": "Sunday Morning Hockey",
"location": {
"type": "Point",
"coordinates": [
39,
-105
]
},
"events": "hockey",
"time": "09:00",
"recurring": "true",
"date": "2020-08-02",
"difficulty": "all levels",
"ages": "all ages",
"admin": "1000",
"private": "false",
"_rid": "Maw1AIaRiRoBAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoBAAAAAAAAAA==/",
"_etag": "\"13008c9f-0000-0700-0000-5f3050d70000\"",
"_attachments": "attachments/",
"_ts": 1597001943
}
{
"id": "9f373e04-0cfc-4121-927d-a6256dbe06c6",
"name": "test1",
"location": {
"type": "Point",
"coordinates": [
39.731441899363105,
-104.98381230980158
]
},
"events": "Basketball",
"time": "00:00:00",
"recurring": null,
"date": null,
"difficulty": "Expert",
"ages": "Adult",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoLAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoLAAAAAAAAAA==/",
"_etag": "\"13005999-0000-0700-0000-5f304d760000\"",
"_attachments": "attachments/",
"_ts": 1597001078
}
{
"id": "be01bc12-d28e-4368-b6de-0f3e84dbe13c",
"name": "test2",
"location": {
"type": "Point",
"coordinates": [
39.72082849205111,
-104.98461395502092
]
},
"events": "Hockey",
"time": "00:00:00",
"recurring": null,
"date": null,
"difficulty": "Expert",
"ages": "Adult",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoMAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoMAAAAAAAAAA==/",
"_etag": "\"1300219a-0000-0700-0000-5f304de10000\"",
"_attachments": "attachments/",
"_ts": 1597001185
}
Took a while to realize, but GeoJSON expects flipped coordinates in the Point.
So while Maps return me a point type with [ latitude, longitude ]. GeoJSON expects [longitude, latitude]

Transform Multiple rows of JSON format to SQL table

I have JSON file in Blob Storage that looks like this:
{
"Id": "****************************",
"Status": "OK",
"ProviderName": "Xero API Previewer",
"DateTimeUTC": "\/Date(1576561543598)\/",
"Invoices": [
{
"Type": "ACCPAY",
"InvoiceID": "*****************************",
"InvoiceNumber": "457489",
"Reference": "",
"Payments": [],
"CreditNotes": [],
"Prepayments": [],
"Overpayments": [],
"AmountDue": 0.00,
"AmountPaid": 0.00,
"AmountCredited": 0.00,
"CurrencyRate": 1.000000,
"IsDiscounted": false,
"HasAttachments": false,
"HasErrors": false,
"Contact": {
"ContactID": "************************************",
"Name": "********************",
"Addresses": [],
"Phones": [],
"ContactGroups": [],
"ContactPersons": [],
"HasValidationErrors": false
},
"DateString": "2102-11-26T00:00:00",
"Date": "\/Date(4193942400000+0000)\/",
"DueDateString": "2012-11-28T00:00:00",
"DueDate": "\/Date(1354060800000+0000)\/",
"Status": "VOIDED",
"LineAmountTypes": "Inclusive",
"LineItems": [
{
"Description": "Parking ",
"UnitAmount": 465.01,
"TaxType": "INPUT2",
"TaxAmount": 60.65,
"LineAmount": 465.01,
"AccountCode": "274",
"Tracking": [
{
"Name": "Region",
"Option": "New Zealand",
"TrackingCategoryID": "****************************************",
"Options": []
},
{
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "***************************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "**************************************"
}
],
"SubTotal": 404.36,
"TotalTax": 60.65,
"Total": 465.01,
"UpdatedDateUTC": "\/Date(1355876228590+0000)\/",
"CurrencyCode": "NZD"
},
{
"Type": "ACCPAY",
"InvoiceID": "**************************************",
"InvoiceNumber": "176295-01",
"Reference": "",
"Payments": [
{
"PaymentID": "********************************************",
"Date": "\/Date(1576454400000+0000)\/",
"Amount": 137.43,
"Reference": "",
"CurrencyRate": 1.000000,
"HasAccount": false,
"HasValidationErrors": false
}
],
"CreditNotes": [],
"Prepayments": [],
"Overpayments": [],
"AmountDue": 0.00,
"AmountPaid": 137.43,
"AmountCredited": 0.00,
"CurrencyRate": 1.000000,
"IsDiscounted": false,
"HasAttachments": true,
"HasErrors": false,
"Contact": {
"ContactID": "************************************",
"Name": "InkWorks",
"Addresses": [],
"Phones": [],
"ContactGroups": [],
"ContactPersons": [],
"HasValidationErrors": false
},
"DateString": "2019-12-17T00:00:00",
"Date": "\/Date(1576540800000+0000)\/",
"DueDateString": "2020-01-20T00:00:00",
"DueDate": "\/Date(1579478400000+0000)\/",
"Status": "PAID",
"LineAmountTypes": "Inclusive",
"LineItems": [
{
"Description": "general stationery",
"UnitAmount": 137.43,
"TaxType": "INPUT2",
"TaxAmount": 17.93,
"LineAmount": 137.43,
"AccountCode": "273",
"Tracking": [
{
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "******************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "****************************************"
}
],
"SubTotal": 119.50,
"TotalTax": 17.93,
"Total": 137.43,
"UpdatedDateUTC": "\/Date(1576524509820+0000)\/",
"CurrencyCode": "NZD",
"FullyPaidOnDate": "\/Date(1576454400000+0000)\/"
},
I want to store LineItems into a Table with columns as follows:
InvoiceID LineItemID Description LineAmount AccountCode Date
There can be multiple LineItems in a single invoice.
I managed to get the top level only with the following code.
WITH cte AS (
SELECT CAST (BulkColumn AS NVARCHAR(MAX)) AS jsonData
FROM
OPENROWSET(
BULK 'temp/XeroJson.json',
DATA_SOURCE = 'test'
-- FORMATFILE_DATA_SOURCE = 'test'
, SINGLE_CLOB
) AS blob
)
SELECT *
FROM cte
CROSS APPLY
OPENJSON(cte.jsonData) j
How can I make this work?
This is my test .json file, I placed it in my storage account :
{
"Id": "****************************",
"Status": "OK",
"ProviderName": "Xero API Previewer",
"DateTimeUTC": "\/Date(1576561543598)\/",
"Invoices":
[
{
"Type": "ACCPAY",
"InvoiceID": "123456",
"InvoiceNumber": "457489",
"Reference": "",
"Payments": [],
"CreditNotes": [],
"Prepayments": [],
"Overpayments": [],
"AmountDue": 0.00,
"AmountPaid": 0.00,
"AmountCredited": 0.00,
"CurrencyRate": 1.000000,
"IsDiscounted": false,
"HasAttachments": false,
"HasErrors": false,
"Contact": {
"ContactID": "************************************",
"Name": "********************",
"Addresses": [],
"Phones": [],
"ContactGroups": [],
"ContactPersons": [],
"HasValidationErrors": false
},
"DateString": "2102-11-26T00:00:00",
"Date": "\/Date(4193942400000+0000)\/",
"DueDateString": "2012-11-28T00:00:00",
"DueDate": "\/Date(1354060800000+0000)\/",
"Status": "VOIDED",
"LineAmountTypes": "Inclusive",
"LineItems": [{
"Description": "Parking ",
"UnitAmount": 465.01,
"TaxType": "INPUT2",
"TaxAmount": 60.65,
"LineAmount": 465.01,
"AccountCode": "274",
"Tracking": [{
"Name": "Region",
"Option": "New Zealand",
"TrackingCategoryID": "****************************************",
"Options": []
}, {
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "***************************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "**************************************"
},
{
"Description": "Parking2 ",
"UnitAmount": 111.11,
"TaxType": "INPUT2",
"TaxAmount": 60.65,
"LineAmount": 465.01,
"AccountCode": "276",
"Tracking": [{
"Name": "Region",
"Option": "New Zealand",
"TrackingCategoryID": "****************************************",
"Options": []
}, {
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "***************************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "**************************************"
}
],
"SubTotal": 404.36,
"TotalTax": 60.65,
"Total": 465.01,
"UpdatedDateUTC": "\/Date(1355876228590+0000)\/",
"CurrencyCode": "NZD"
},
{
"Type": "ACCPAY",
"InvoiceID": "1234567",
"InvoiceNumber": "176295-01",
"Reference": "",
"Payments": [{
"PaymentID": "********************************************",
"Date": "\/Date(1576454400000+0000)\/",
"Amount": 137.43,
"Reference": "",
"CurrencyRate": 1.000000,
"HasAccount": false,
"HasValidationErrors": false
}
],
"CreditNotes": [],
"Prepayments": [],
"Overpayments": [],
"AmountDue": 0.00,
"AmountPaid": 137.43,
"AmountCredited": 0.00,
"CurrencyRate": 1.000000,
"IsDiscounted": false,
"HasAttachments": true,
"HasErrors": false,
"Contact": {
"ContactID": "************************************",
"Name": "InkWorks",
"Addresses": [],
"Phones": [],
"ContactGroups": [],
"ContactPersons": [],
"HasValidationErrors": false
},
"DateString": "2019-12-17T00:00:00",
"Date": "\/Date(1576540800000+0000)\/",
"DueDateString": "2020-01-20T00:00:00",
"DueDate": "\/Date(1579478400000+0000)\/",
"Status": "PAID",
"LineAmountTypes": "Inclusive",
"LineItems": [{
"Description": "general stationery",
"UnitAmount": 137.43,
"TaxType": "INPUT2",
"TaxAmount": 17.93,
"LineAmount": 137.43,
"AccountCode": "273",
"Tracking": [{
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "******************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "****************************************"
}
],
"SubTotal": 119.50,
"TotalTax": 17.93,
"Total": 137.43,
"UpdatedDateUTC": "\/Date(1576524509820+0000)\/",
"CurrencyCode": "NZD",
"FullyPaidOnDate": "\/Date(1576454400000+0000)\/"
}
]
}
As you can see the first invoice has two lineItems for demo here.
This is my sql script to exract from the json from storage :
CREATE DATABASE SCOPED CREDENTIAL AccessAzureInvoices
WITH
IDENTITY = 'SHARED ACCESS SIGNATURE'
-- REMOVE ? FROM THE BEGINNING OF THE SAS TOKEN
, SECRET = '<YOUR STORAGE SAS TOKEN>'
;
CREATE EXTERNAL DATA SOURCE MyAzureInvoices
WITH
( LOCATION = 'https://<YOUR STORAGE NAME>.blob.core.windows.net/<CONTAINER NAME WHERE YOUR JSON FILE IN>'
, CREDENTIAL = AccessAzureInvoices
, TYPE = BLOB_STORAGE
)
;
DECLARE #jsonVariable NVARCHAR(MAX);
set #jsonVariable = (select * from OPENROWSET(
BULK '<YOUR JSON FILE NAME>.json',
DATA_SOURCE = 'MyAzureInvoices',
SINGLE_CLOB
) AS blob)
select * from (
SELECT *
FROM OPENJSON(#jsonVariable,N'$.Invoices') WITH (
InvoiceID VARCHAR(200) N'$.InvoiceID',
Date VARCHAR(200) N'$.Date',
LineItems NVARCHAR(MAX) N'$.LineItems' as json
))as table1
CROSS APPLY OPENJSON(LineItems) with (
LineAmount VARCHAR(200) '$.LineAmount',
AccountCode VARCHAR(200)'$.AccountCode',
LineItemID VARCHAR(200) '$.LineItemID',
Description VARCHAR(200) '$.Description'
)
Result :
Hope it helps !