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.

 View Only
  • 1.  Form Data to Xml transformation in API CONNWCT

    Posted Sun June 07, 2020 02:25 PM
    Hi, 
    I want to convert incoming payload formdata application/www-Url-encode to xml in API Connect? Can you please help me with the available option to do that?

    ------------------------------
    Jeeva S
    ------------------------------


  • 2.  RE: Form Data to Xml transformation in API CONNWCT

    Posted Tue June 09, 2020 10:30 AM

    Hi Jeeva.

    The correct MIME type is application/x-www-form-urlencoded use it instead the one that you wrote ;-)

    There is not a parser for that MIME type, so I'm afraid that it will be not as simple as drop a box in the assembly. Your question was answered on the IBM support (https://www.ibm.com/support/pages/support-web-form-api-connect-post-http-requests-applicationx-www-form-urlencoded-and-multipartform-data-content-types) a year ago, but the answer is the same; the RFE that is pointing was rejected (https://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=91616).

    You'll have to write a gateway script, check the code example on the IBM support page linked above. 



    ------------------------------
    Daniel Castellano Bonilla
    ------------------------------



  • 3.  RE: Form Data to Xml transformation in API CONNWCT

    Posted Wed June 10, 2020 06:16 AM
    Thanks You !! I will try that.

    ------------------------------
    Jeeva S
    ------------------------------



  • 4.  RE: Form Data to Xml transformation in API CONNWCT

    Posted Mon February 21, 2022 09:08 AM
    Hi Daniel,

    Is it support passthrough with content type application/www-Url-encode in APIC (allow request form data and pass as it is backend)

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



  • 5.  RE: Form Data to Xml transformation in API CONNWCT

    Posted Wed March 30, 2022 09:43 AM

    Hi Jeeva,

    In addition to the support tech note Daniel provided, GatewayScript supports the querystring module, see https://www.ibm.com/docs/en/datapower-gateway/10.0.x?topic=apis-querystring-module, and specifically the parse function of that module is of interest.  Here is a simple example as shown from within the GatewayScript CLI debugger:

    (debug)
      1:let querystring = require('querystring');
      2:let requestBody = context.get('request.body');
      3:let requestBodyJSON = querystring.parse(requestBody.toString());
    =>4:debugger;
    (debug) p requestBody.toString()
    p1=value1&p2=value%2Bwithplus
    (debug) p requestBodyJSON
    { p1: 'value1', p2: 'value+withplus' }
    

    this happens to be a v10 API Gateway  example, thus the payload is retrieved with a context.get.  The value for p2 also has an encoded character.  The parse function returns a JSON object with the parameter names as the property keys, and the values are JSON decoded values, so what the tech note showed by doing your own parsing by splitting on the & and iterating over this list by splitting on the = and then decoding the value, you can do in a single instruction.

    Regards,
    Steve



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