Thanks Steve for your suggestion.
only one set of action and it did the trick.
To be precise, I kept mapping at the field level instead of array level.
Thanks once again to help me out. π
Original Message:
Sent: Thu March 21, 2024 08:57 AM
From: Steve Linn
Subject: Map policy for Array
Hi Monica,
When you wire an array to an array in the map policy, it generates a create action in the map actions. The create action is effectively an "add this mapping to any already create array output items". For example, you could have two separate arrays in your input, and both could be wired to the same output array. In this case, the first create would generate 1..n output array elements, and the second create would add to those with the 1.n array elements from the 2nd input. So what's happening in your case. You have two actions in your map policy.
- set: parameters.initiateKYCEngineRq.party_requirements.Products from: initiateKYCRequest.party_requirements.Products - create: >- parameters.initiateKYCEngineRq.party_requirements.Products.Product foreach: initiateKYCRequest.party_requirements.Products.Product from: initiateKYCRequest.party_requirements.Products.Product actions: - set: $item from: $item - set: Product_Business_Unit from: Product_Business_Unit - set: Product_Group__c from: Product_Group__c
The set is effectively copying your input Products object, including the child Product array, to the same structure in your output object. Now your output has one product element. The create then does the specific mapping for the array, but it is taking from the same input array and mapping to the same output array, which would be why you're seeing the duplicate.
So in your case since the mapping is so simple, you can remove one or the other action. If your output schema is different, for example, the input array element objects use different names than the output array element objects, then the set action would be putting into your output objects with an incorrect output name and you'd need to eliminate that one, but in your case where everything appears to be identical between the input and output schemas, removing either action should do the trick.
Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Fri March 15, 2024 11:55 AM
From: Monica Deo
Subject: Map policy for Array
hi there,
I am new to API connect, I am using OPEN API 2.0, I appreciate if you can help me to resolve one problem.
I am getting an issue with an array in the request message.
When I call my BAW API via API connect , it duplicates the array elements. but when I run the API directly through BAW it gives expected results.
To elaborate my question, for example, I have a Products object in my request message, and within this object ,I have an array of type Product, Inline Schema representation of this object in API designer is:
"Products": {
"type": "object",
"properties": {
"Product": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Product_Business_Unit": {
"type": "string",
"name": "Product_Business_Unit"
},
"Product_Group__c": {
"type": "string",
"name": "Product_Group__c"
}
}
},
"name": "Product"
}
},
"name": "Products"
},
and Source representation is:
set: parameters.initiateKYCEngineRq.party_requirements.Products
from: initiateKYCRequest.party_requirements.Products
- create: >-
parameters.initiateKYCEngineRq.party_requirements.Products.Product
foreach: initiateKYCRequest.party_requirements.Products.Product
from: initiateKYCRequest.party_requirements.Products.Product
actions:
- set: $item
from: $item
- set: Product_Business_Unit
from: Product_Business_Unit
- set: Product_Group__c
from: Product_Group__c

I am sending the array in the request message with one element
"Products": { "Product": [
{
"Product_Business_Unit": "c",
"Product_Group__c": ""
}
]},
but it gets duplicated when it passes through API gateway(map policy) :
"Products": {
"Product": [
{
"Product_Group__c": "",
"Product_Business_Unit": "c"
},
{
"Product_Group__c": "",
"Product_Business_Unit": "c"
}
]
}
},
Please advice what is causing this duplication of array elements. it is doing the same for all other arrays in the request message.
I would appreciate your help and guidance here.
Thanks and Regards,
Monica
------------------------------
Monica Deo
------------------------------