API Connect

 View Only
  • 1.  How to call file using fs module in APIC

    Posted Tue February 15, 2022 02:28 PM
    We tried below code for Datapower and it is working fine, same code is not working with APIC, it is getting apim.gatewayscript: Syntax Error: invalid or Unexpected token error is coming.

    Gateway script code:

    var fs = require('fs')
    fs.readAsJSON("local:///fingerprintsinfo.json", function(error,data) {
    if (error) {
    // Handle the error.
    } else {
    var abc = 'kandula-nagababu_Sample.clientfingerprint';
    // this can read the file .file and .json also
    console.error('Data read:'+data.abc+"\n");
    session.output.write(data[abc]);
    }
    });

    fingerprintsinfo.json: 
    {
    "kandula-nagababu_Sample": {
    "bankfingerprint": "XP1BfIqHDn3HXb",
    "clientfingerprint": "/KfAfYgOTnlkJLuK"
    }
    }

    ------------------------------
    kandula nagababu
    ------------------------------


  • 2.  RE: How to call file using fs module in APIC

    IBM Champion
    Posted Tue February 15, 2022 04:19 PM
    Hi kandula, 
    Unfortunately, fs module is not supported in the API Gateway. You can find the detailed list of supported modules here:
    Gateway programming model and GatewayScript - IBM Documentation

    For your use case, you can utilize catalog properties for storing such information, and retrieve them on runtime. 


    ------------------------------
    Romil Garg
    ------------------------------



  • 3.  RE: How to call file using fs module in APIC

    Posted Wed February 16, 2022 02:03 AM
    Edited by kandula nagababu Thu February 17, 2022 02:04 AM
    Hi Romil Garg,

    Thank you for your response.

    How can we use DP functions in Gateway script
    dp:get-cert-thumbprintsha1(concat('name:',$certDetails))

    is there any possibility to call inside Gateway script xslt code in APIC,like inside the xslt we can able to call Gatewayscript in DP? 
    I think it is not possible because of we are not able to give file reference in APIC (not support fs module)

    Please provide response on DP functions usage in Gateway script.
    ------------------------------
    kandula nagababu
    ------------------------------



  • 4.  RE: How to call file using fs module in APIC

    Posted Thu April 28, 2022 08:56 AM
    Dear Nagababu,

    Yes you can execute xslt using Gatewayscript, IBM Datapower already has built in node module Transform, this module you can reference your xsl stylesheet location. Also pass your xmldom with filepath. As you need you can use this module in IBM API Connect.

    --------------------
    Jayprakash Yadav

    ------------------------------
    Jayprakash Yadav
    ------------------------------



  • 5.  RE: How to call file using fs module in APIC

    Posted Thu April 28, 2022 08:56 AM
    Also fs module could not be loaded in API Gateway service, you can do what store the file write and file read script at Datapower file management, and execute from Gatewayscript node in IBM API Connect.

    ------------------------------
    Jayprakash Yadav
    ------------------------------



  • 6.  RE: How to call file using fs module in APIC

    Posted Fri April 29, 2022 12:05 PM

    Hi Kandula,

    As you're only trying to read the file, within your GatewayScript policy instead of trying to use the fs module you can use the urlopen module to read the local file.  See https://www.ibm.com/docs/en/datapower-gateway/10.0.1?topic=apis-urlopen-module and look for the section "urlopen.open() to open files on the DataPower Gateway".  You can then do a readAsJSON on your response.

    Regards,
    Steve



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