i am new to K6 , In my script , i have a POST request where i need to parametrize certain values like phone number , account number …etc ,
the payload looks as below
{
“RequestType”: “Association”,
“Version”: “V1”,
“AssociateAccount”: [
{
“accId”: “12365498”,
“encryptedsecuritycode”: “MTIzZXJkdA==”,
“phonenum”: “6756453782”,
“originator”: “dummy”
}
]
}
My have created below script , however when i am running it the value is not getting passed in request rather the variable name is getting passed ,
import { sleep, check } from ‘k6’;
import http from ‘k6/http’;
import papaparse from ‘https://jslib.k6.io/papaparse/5.1.1/index.js’;
import { SharedArray } from ‘k6/data’;
const data = new SharedArray(‘phonenumber’, function () {
return JSON.parse(open(‘./CstData.json’)).phoneno;
});
export default function main() {
const randomPhNo = data[Math.floor(Math.random() * data.length)];
console.log(randomPhNo);
let response;
response = http.post(
“http://88.20.131.129/pos/store”,
‘{\r\n “RequestType”: “Association”,\r\n “Version”: “V1”,\r\n “AssociateAccount”: [\r\n {\r\n “accId”: “12365498”,\r\n “encryptedsecuritycode”: “MTIzZXJkdA==”,\r\n “phonenum”: “${randomPhNo}”,\r\n “originator”: “dummy”\r\n }\r\n ]\r\n}’,
{
headers: {
Accept: “application/json”,
“Content-Type”: “application/json”,
“X-Payment-experimentation”: “V1”,
},
});
sleep(2);
}
Could you please help?
Thanks in advance!