API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#API Connect
#Applicationintegration
#APIConnect
 View Only
  • 1.  Map Transform to create action for processing elements in an array

    Posted 06/11/23 03:15 AM
      |   view attached

    Hi Steve...

    We are using the map transform to create action for processing elements in an array, where a particular field in an array response needs some modification in gateway script. we are encrypting the field and sending the final response. 

    Attached is the snippet for the code, issue we are facing is that we are not able to access the value of the field from input array not sure if the way we are accessing the field in the gateway script is correct. Please advise




    ------------------------------
    Ashok Beshra
    ------------------------------


  • 2.  RE: Map Transform to create action for processing elements in an array

    Posted 06/12/23 09:46 AM

    Hi Ashok,
    What does your input data look like?  Looking at your "Iterate over" in your screen shot, I'd anticipate seeing that property AcctBal is an array of primitives (string, number).  For example "AcctBal": [1234, 5678].  That is why you see $item in the child mapping as each individual array element you are iterating over does not have a property name, so the map policy uses $item to reference unnamed properties.  Is this correct or does your input schema not match your input data as far as this array is concerned?  If you provided the full map policy so I can see the input schema and a sample input payload I can make a better determination of what the issue is.
    Best Regards,

    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 3.  RE: Map Transform to create action for processing elements in an array

    Posted 06/13/23 09:49 AM
      |   view attached

    Hi Steve...

     AcctBal is an array of primitives (string, number), the proeprty name is present as [BalType, BalAmt]. Below is the code we have written in the map policy and attached is the map policy.

     

    Map policy Code:
    ===============
    var retValue = undefined;
    if ($(BalAmt) !== null) {
    var randomNo = apim.getvariable('randomNo');
    var IV = apim.getvariable('IV');
    var crypto = require('crypto');
    var cipher = crypto.createCipheriv('aes256-cbc',Buffer.from(randomNo, 'utf8'),Buffer.from(IV, 'utf8'));
    var ciph = cipher.update($(BalAmt),'utf8');
    retValue = ciph.final('base64');
    }
     
    Error received:
    ===============
     
    5:37:41 PM apiconnect error 70993247 request 10.9.63.211 0x85a0000a apigw (APICSIT): Map: API=accountinquiry, policy=mapFetchAccountDtlsRes : set action $item: invalid value expression and no default configured. {"set":"$item","from":"$item","value":"var retValue = undefined;\r\nif ($(BalAmt) !== null) {\r\n\t\tvar randomNo = apim.getvariable('randomNo');\r\n\t\tvar IV = apim.getvariable('IV');\r\n\t\tvar crypto = require('crypto');\r\n\t\tvar cipher = crypto.createCipheriv('aes256-cbc',Buffer.from(randomNo, 'utf8'),Buffer.from(IV, 'utf8'));\r\n\t\tvar ciph = cipher.update($(BalAmt),'utf8');\r\n\t\tretValue = ciph.final('base64');\r\n}"}
     
    5:37:41 PM apiconnect error 70993247 request 10.9.63.211 0x8580005c apigw (APICSIT): Map: API=accountinquiry, policy=mapFetchAccountDtlsRes : set action $item: invalid valueString expression: var retValue = undefined; if (BalAmt !== null) { var randomNo = apim.getvariable('randomNo'); var IV = apim.getvariable('IV'); var crypto = require('crypto'); var cipher = crypto.createCipheriv('aes256-cbc',Buffer.from(randomNo, 'utf8'),Buffer.from(IV, 'utf8')); var ciph = cipher.update(BalAmt,'utf8'); retValue = ciph.final('base64'); }


    ------------------------------
    Ashok Beshra
    ------------------------------

    Attachment(s)

    yaml
    mappolicy.yaml   29 KB 1 version


  • 4.  RE: Map Transform to create action for processing elements in an array

    Posted 06/16/23 01:31 PM

    Hi Steve...

    Let me know if you require any additional details on this. Thanks.



    ------------------------------
    Ashok Beshra
    ------------------------------