Some help on that would be very useful, thank you.
I have tried to pull the request header from another test in the Tests tab after a collection request executed successfully and use that, but I am obviously not doing it correctly. I have a lot to learn about authorization and headers in particular I guess.
I assume I need to extract parts of the authorization header and use that in the pm.sendRequest…?
I’d start with this article to get you set up for automating your OAuth token acquisition/renewal. It will also add your JWT in a variable, which you can then use in your pre-request script.
I’m also missing the feature that authorization is inherited in pre-request scripts. My use case is a bit different. When sending a modifying OData request (POST, PUT, PATCH …) I need to send an CSRF token in the header. So far I have a separate HEAD request to the OData service document URL in my collection to fetch an CSRF token and then store in a variable. The modifying request will get the CSRF token from the variable.
That approach works fine but I want to automate the HEAD request with a pre-requisite script. That is basically already working. I use pm.request.clone(); to get a new request, change the method to “HEAD” and shorten the URL to the service document and then use this request to fetch the token. Unfortunately this only works if the authorization information are provided on the request itself. It does not work if authorization is set to “inherit from parent”. Is there any way to retrieve the authorization information from the parent (folder, collection) in the pre-request script?