API Connect

 View Only
  • 1.  unable to capture value from request header using gateway script

    Posted Tue November 16, 2021 05:16 AM
    Hello Everyone,

    We have created two parameter(Authorization, Checksum) which is passed through request header  & we want to validate value using gateway script.

    We used below code to capture value from request header

    var store = apim.getvariable('request.headers.Authorization');

    session.output.write(store);

    apim.output('*/*');

    but getting undefined response from APIC v5 in IBM cloud.

    so please advice for the same

    ------------------------------
    Akshay Sawant
    ------------------------------


  • 2.  RE: unable to capture value from request header using gateway script

    Posted Mon November 22, 2021 05:18 PM
    Edited by Steve Linn Mon November 22, 2021 05:18 PM

    I suspect that the apim.output argument value of */* may be the issue.  This function will a) tell the v5 framework that the policy has written output which must be captured in message.body and b) provides the actual content type of the data written.   Please try apim.output('text/plain'); and see if that makes a difference.

    Regards,

    Steve



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



  • 3.  RE: unable to capture value from request header using gateway script

    IBM Champion
    Posted Tue November 23, 2021 07:01 AM
    Also, make sure you are defining apim method. If no success, try printing the variable to verify that you are able to fetch the header successfully.


  • 4.  RE: unable to capture value from request header using gateway script

    Posted Tue November 23, 2021 01:39 PM

    Although my previous comment about the apim.output function argument is valid in that it should describe the output that you're writing, ie, text/plain instead of */*, it is not the cause of your issue.  The cause is a simple case sensitivity issue.  In v5, request headers are saved internally with lower cased names, and apim.getvariable is case sensitive.  Simply change

    var store = apim.getvariable('request.headers.Authorization');

    to

    var store = apim.getvariable('request.headers.authorization');

    and your header value should be available to you.

    Regards,

    Steve



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