Rayrun
โ† Back to Discord Forum

Adding key value pair as auth in api header

Curreently struggling with how to pass through to my, an API key value pair as the Authorization of my API call. Any thoughts or docs on this. I'm struggling to find something that works. I have tried adding a header with the key and value but I must not be doing this right.

This thread is trying to answer question "How to pass an API key value pair as the Authorization of an API call?"

5 replies

tried adding headers to the request context options, no luck

tried adding to the context.post options. Also no luck

This might work for you https://playwright.dev/docs/api/class-testoptions#test-options-extra-http-headers

I have used this in my project configuration, but if you are creating a new request context you will need to pass the same logic in on the constructor.

Sample config code use: { extraHTTPHeaders: { 'my-secret': ${process.env.MY_SECRET} } },

Sample new context: const context: APIRequestContext = await request.newContext({ extraHTTPHeaders: { 'my-secret': ${process.env.MY_SECRET} } });

If this is not your issue and you are looking to just add additional key value pairs to you header I can give you some code sample, but I am assuming you want to add some kind of token to all your API headers.

thanks. Yer I added the extraHTTPHeaders against the context ๐Ÿ‘

I thought i had tried this and it didnt work but i may have got a name wrong. Anyway, thanks for ya response.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.