Problems with searchParams in URL

I have K6-code that tries to parameterize a value to a URL. Here are some code snippets.

const csvDataPatients = new SharedArray('patients', function () {return papaparse.parse(open('../testdata/patients.csv'), { header: true }).data;});
.
.
.

   const randomPatient = csvDataPatients[Math.floor(Math.random() * csvDataPatients.length)];
    urlProxy.searchParams.append('test_pid', randomPatient);
.
.
.
console.log((urlProxy));

The problem is that console.log print this:

INFO[0000] "https://dev.xx.xx.xx.xx/hpp-webapp/careplan/proxy/login?test_pid=%5Bobject+Object%5D"  source=console

The value seems to be encoded wrong?

What happens if you console.log(JSON.stringify(randomPatient)))? Because it seems like it’s not a simple ID, but rather an Object of some sort.

INFO[0000] {“fnr”:“05085600143”}

And:
console.log(JSON.stringify(urlProxy))
Gives me:
INFO[0000] “https://xxx/careplan/proxy/login?test_pid=[object+Object]

Just use randomPatient.fnr then?

Hmm,
Where in my script?

const csvDataPatients = new SharedArray('patients', function () {return papaparse.parse(open('../testdata/patients.csv'), { header: true }).data;});
const csvDataHp = new SharedArray('hp', function () {return papaparse.parse(open('../testdata/hp.csv'), { header: true }).data;});



export default function main() {
    let response
    const vars = {}
    const urlProxy = new URL('https://xxx/careplan/proxy/login');
    const randomPatient = csvDataPatients[Math.floor(Math.random() * csvDataPatients.length)];
    urlProxy.searchParams.append('test_pid', randomPatient);




    console.log((randomPatient));
    //console.log(JSON.stringify(urlProxy))
    //console.log((urlProxy));

    group(
        'careplan_proxy_login',
        function () {
            response = http.get(urlProxy.toString()),
                {
                    headers: {

Where you add it to the URL:

urlProxy.searchParams.append(‘test_pid’, randomPatient.fnr);
Gives me “unresolved variable”

Maybe you don’t have fnr on some randomPatient rows? :man_shrugging: I am sorry, but I can’t debug your script in this way, message by message. I suggest you add some checks and console.log() statements and see where the problem lies that way…

Ok, fnr is the heading of the csv file, like this:

fnr
13116900216
05085600143