Best way to base64 encode user & Password in Authorization HTTP request?


I want to encode the user and password for issuing a token request in the setup, so I can use it in all the tests.
Usually it has the shape of “user:password” >> Encoded to Base64 is “dXNlcjpwYXNzd29yZA==” done with Base64 Encode and Decode - Online

What is the best way to do this in a K6 script?
btoa(“user:password”) does not seem to work…
reference: How to Encode and Decode Strings with Base64 in JavaScript (

Is there any way that avoids me to do all the base64 encoding by myself? :slight_smile:


Hi @joslat,
you can encode using Base64 using the Javascript API invoking the b64encode function from the encoding module.

Here, an explicit example of how to use it for Basic authentication.