I am unclear whether I needed to implement the prior 'solutions' but the (last?) solution to this was to manually set the PHPSESSID cookie as follows.
Cypress framework > api-utilities.ts
const configuration = {
headers: {
'Content-Type': 'application/json',
Cookie: ''
}
}
then
to the logIn method in the class to set the cookie in the configuration
variable.await this.callApi('https://localhost/xyz/php/apis/users.php', ApiCallMethods.POST, {
action: 'log_in',
username: 'censored',
password: 'censored'
}).then(response => {
const phpSessionId = response.headers['set-cookie'][0].match(new RegExp(/(PHPSESSID=[^;]+)/))
configuration.headers.Cookie = phpSessionId[1]
})
configuration
variable in the callApi method.axios.post(url, data, configuration)
Success:
Logging in...
Sent headers: Object [AxiosHeaders] {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
Cookie: ''
}
Received headers:
set-cookie: PHPSESSID=e7ik1oqt7f5j48sn0lonoh5slb; expires=Wed, 05 Feb 2025 16:47:27 GMT; Max-Age=3600;
Data:
{
ResponseType: 'redirect',
URL: 'http://localhost/xyz/php/pages/games.php',
'logged in:': true
}
Subsequent API call...
Sent headers: Object [AxiosHeaders] {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
Cookie: 'PHPSESSID=e7ik1oqt7f5j48sn0lonoh5slb'
}
Received headers:
**{no PHPSESSID because its using the one acquired by the logIn method}**
Data:
{"PHP > logged in?":true}
{"ResponseType":"redirect","URL":"http:\/\/localhost\/xyz\/php\/pages\/games.php","Id":"64"}