DataPower

DataPower

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
Expand all | Collapse all

Posting form-data using dp:url-open from XSLT in Datapower

  • 1.  Posting form-data using dp:url-open from XSLT in Datapower

    Posted Thu November 12, 2020 06:52 AM

    Hi Experts,

    I have a cURL as below for form-data POST. How can I use it with dp-url open and post form-data. The response of this post is JSON, how to handle it ?

    https://someweb.com/data/v1/oauth2/token \

    -H 'Content-Type: application/x-www-form-urlencoded' \

    -d 'client_id=bla-043C-654-F654-534' \

    -d 'client_secret=ABCD234-654-654DK-BC-498646' \

    -d 'grant_type=client_credentials'



    #DataPower
    #Support
    #SupportMigration


  • 2.  RE: Posting form-data using dp:url-open from XSLT in Datapower

    Posted Fri November 13, 2020 12:54 PM

    Hi,

    check out an earlier thread and see it is works for you: https://www.ibm.com/mysupport/s/forumsquestion?id=0D50z00006fhWezCAE

    If you'll get a JSON response, just change the code into readAsJSON instead of readAsBuffer.

    --HP



    #DataPower
    #Support
    #SupportMigration


  • 3.  RE: Posting form-data using dp:url-open from XSLT in Datapower

    Posted Mon November 16, 2020 01:43 PM

    Do you need dp:url-open into xslt or gatewayscipt ?



    #DataPower
    #Support
    #SupportMigration


  • 4.  RE: Posting form-data using dp:url-open from XSLT in Datapower

    Posted Mon November 16, 2020 02:05 PM

    Hi ​D,

    I am trying in XSLT. 



    #DataPower
    #Support
    #SupportMigration


  • 5.  RE: Posting form-data using dp:url-open from XSLT in Datapower

    Posted Mon November 16, 2020 04:34 PM

    try this


    <xsl:variable name="client_id" select="'bla-043C-654-F654-534'"/>

    <xsl:variable name="client_secret" select="'ABCD234-654-654DK-BC-498646'"/>

    <xsl:variable name="grant_type" select="'client_credentials'"/>

    <xsl:variable name="POST">

    <xsl:text>client_id=</xsl:text>

    <xsl:value-of select="$client_id" disable-output-escaping="yes"/>

    <xsl:text>&amp;client_secret=</xsl:text>

    <xsl:value-of select="$client_secret" disable-output-escaping="yes"/>

    <xsl:text>grant_type=</xsl:text>

    <xsl:value-of select="$grant_type" disable-output-escaping="yes"/>

    </xsl:variable>

    <xsl:variable name="url" select="'https://someweb.com/data/v1/oauth2/token'"/>

    <xsl:variable name="callServeurAuth">

    <dp:url-open target="{$url}" response="responsecode-binary" content-type="application/x-www-form-urlencoded" ssl-proxy="BACK_SSL" http-method="POST" data-type="base64">

    <xsl:value-of select="dp:encode($POST, 'base-64')"/>

    </dp:url-open>

    </xsl:variable>

    <xsl:copy-of select="dp:stringToJSONx(dp:decode(dp:binary-encode($callServeurAuth/result/binary/node()),'base-64'))"/>

    <!--<xsl:copy-of select="dp:binaryNodeToJSONx(dp:binary-decode(dp:binary-encode($callServeurAuth/result/binary/node())))"/>-->



    #DataPower
    #Support
    #SupportMigration