The application itself is similar to Facebook where the user needs to log in and can access different features of the app, such as Marketplace. I'm trying to run API performance tests on the application on a specific feature which calls a POST request. The POST request can be found via Swagger, and I'm using I'm trying test run k6 performance metrics on that POST request, however I'm getting a 401 unauthorized error. Here's my code:
import http from 'k6/http';
import { check } from 'k6';
export default async function getTransactions() {
const res = http.get('https://xxxxxx.net/xxxxx/xxxxxx/xxxx/xxxx/action?email=xxxxx&password=xxxxxx');
check(res, { 'status was 200': (r) => r.status == 200 });
const url = 'https://xxxxxx/api/jr/txn/session/v1'
const payload = JSON.stringify({
"atmId": [
4
],
"devtime0": 20231101000000,
"devtime1": 20231111000000
});
const params = {
headers: {
'accept': '*/*',
'access-control-allow-origin': '*',
'content-type': 'application/json' ,
'server': 'nginx/1.25.3',
},
};
const transactionRes = http.post(url, payload, params)
console.log(transactionRes.body);
check(transactionRes, {'single transaction endpoint reached': (r) => r.status == 200});
}
I've tried getting authorization first with the GET call to the login page with the email and password needed to log in. I was hoping the cookies received back from that session would give me authorization to test an API endpoint with a POST call. I've been met with a 401 error instead however. My next suspicion is that I need an API key or token to proceed further. Would much appreciate guidance on how to proceed further with this!