Topic
  • 2 replies
  • Latest Post - ‏2019-08-18T09:33:49Z by HermannSW
Todd556
Todd556
23 Posts

Pinned topic gateway script to retrieve headers

‏2019-08-06T13:51:41Z | gateway headers script

Hi friends,

 

Need to retrieve headers of an API call via gateway script.

 

 

Currently we are using different headers configurations:

1. Basic Authorization headers (username and pass) // not having problem with this

2. Normal headers - 

          key - Authorization value - Bearer AAIkNTYzOTk4OWItNTU1My00NDMzLWE5NjUtYmQ3NDZmMGY2ZTY34uoi2mc9Bg4rwo4BNXAdwyb- (Token)

 

Currently I retrive headers of category and its value by the following code:

 

var  Category = apim.getvariable('message.headers.Category');    /// Able to successfully get this value

 

But when I use the same for Authorization ; I do not get that token..

 

Also i tried other alternatives

 

var hm = require('header-metadata');
var Authorization = hm.current.get('Authorization');
myAppConsoleLog.error('InpToken=' + Authorization);

 and
var  InpToken = apim.getvariable('message.headers.Authorization');

Kindly suggest. Thanks in advance

 

FYI: I create Token using Provider APis and that Token is passsed on API call in headers along with category as header

  • swlinn
    swlinn
    1445 Posts

    Re: gateway script to retrieve headers

    ‏2019-08-15T16:13:20Z  

    This is a question related to headers in api connect, but I'll ask where is the Authorization header coming from?  If from the client, I would think apim.getvariable('request.headers.Authorization'); would work.  Depending upon what the API does the protocol headers may change, for example an invoke policy would remove all of the "current" headers and replace them with the response headers from the backend server.  That could be the same reason why your direct use of the header-metadata module is also not retrieving this header, but if you specified hm.original.get('Authorization') that would pull the header from the actual client request headers, which is in api connect terms the same as request.headers.

    Regards,
    Steve

  • HermannSW
    HermannSW
    8679 Posts

    Re: gateway script to retrieve headers

    ‏2019-08-18T09:33:49Z  
    • swlinn
    • ‏2019-08-15T16:13:20Z

    This is a question related to headers in api connect, but I'll ask where is the Authorization header coming from?  If from the client, I would think apim.getvariable('request.headers.Authorization'); would work.  Depending upon what the API does the protocol headers may change, for example an invoke policy would remove all of the "current" headers and replace them with the response headers from the backend server.  That could be the same reason why your direct use of the header-metadata module is also not retrieving this header, but if you specified hm.original.get('Authorization') that would pull the header from the actual client request headers, which is in api connect terms the same as request.headers.

    Regards,
    Steve

    APIC questions are better stated here:
    https://developer.ibm.com/answers/smart-spaces/11/api.html

    Hermann.