I'm trying to implement an admin request submission class in node.js. There are two API calls, one is Login and the second is Request Access (Both are forms). I've managed to build these two API calls in Postman, however, I'm struggling with getting the same behavior in node.js. Probably because cookies are not passed correctly.
The login flow is: Send POST request to https://{{base_uri}}/hc/web/siteadminlogin/siteadmin/AdminAccess.jsp With form data and Content-Type: application/x-www-form-urlencoded
The response from this call is 302 redirect that sets these two cookies:
Set-Cookie: WSHumanClickWebSession=816d619eddd19ee46ac03bf88b381; path=/hc/web; secure; HttpOnly
Set-Cookie: WSHumanClickServer=z1-e-dnv6969; path=/hc/web; secure
Then the redirect triggers a GET request to the following URL: https://{{base_uri}}/hc/web/siteadmin/siteadmin/AdminAccess.jsp?site={{form_data_site}}
With the cookies from the initial POST response.
Postman handles cookie storage automatically, however, in Axios these cookies are not passed correctly to the 302 redirect. Causing the login to fail and return back to the login page.
This is what I have in node:
const qs = require('qs');
const data = qs.stringify({
'user_name': 'user_name',
'password': 'user_pass!!',
'site_number': 'site_num',
'But1':'Submit'
});
const config = {
method: 'post',
url: 'https://base_uri/hc/web/siteadminlogin/siteadmin/AdminAccess.jsp',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data : data,
withCredentials: true,
};
try {
const response = await axios(config);
console.log(response.headers);
console.log(response.data);
}catch (e) {
console.log(e)
}
It's either the form data is not being submitted correctly or the cookies are not being stored and passed between the requests. Any ideas on how to solve this?