my auth API is like::
export function authentication() {
let payload = {
"email":"XXXX",
"password":"XXXX"
}
let auth = http.post(`${API_URL}/auth`, JSON.stringify(payload), {
headers: {
"Content-Type": "application/json"
}});
var api_token = JSON.parse(auth.body).token
return api_token
}
And I am trying to use the below code for multiple iterations:
export let options = {
vus: 20,
duration: '50s'
};
API to be tested is ::
export default function() {
// POST
let hotContracts = http.post(`${API_URL}/v1/X`,{},
{ headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${api_token}`}});
//console.log("The body is =>>>> " + X.body);
}
APIs are working fine on their own, but I want to make sure that auth API only runs once.
Can someone please help