How to create Request Headers in Selenium

Hello,

I am sure there is a fix I just cant find it :wink: I know in Palladin you can use the HTTP retriever. How do I set the request header for authorization in Selenium.

Thank you

Hi nxfxcom,

actually, there’s nothing to find :wink: Selenium resp. browsers do not have an API which would allow to add or alter HTTP headers. So this is technically not possible (directly).

Care to explain you scenario, and why you’d need to set headers?

Best,
Philipp

Thank you, fastest customer service ever :wink:

I am trying to collect data from a XHR JSON API. To authenticate I have to send a request header with an authorization token. For some reason, I can’t get it to work in the HTTP Retriever… needs to be in the browser.

1 Like

Thanks for the details and the kind words :slight_smile:

I see two options:

  1. The website from which you want to collect data, obviously requires a login (which then gets you a token which in turn is sent through the headers). You could add the login procedure to the Selenium workflow (i.e. filling login/password into a form, and submitting this). Thus you get the token and the headers will be sent when you access the JSON API.

  2. I still think it should be possible with a “plain” HTTP Retriever node if you set the proper headers, cookies, etc. What kind of error do you currently get? Would you by any chance be able to share an example or the URL so that I could have a look? (if this is not possible, I suggest to check to request within your browser’s dev tools and closely inspect the headers which are sent with the request).

Hope this helps – any further questions let me know!

–Philipp

The API documentation should tell you what to send in the headers. It should tell you what the header key is (the token name for example), and what header value to pass (the token value, or something along with the token value)

Are you able to generate the token at all via the workflow? Or at least retrieve a token some other way, and manually add it as header in your request?

Your workflow should have 2 parts ideally:

  1. Retrieve token
  2. Sent request for api and pass the token in the request