It doesn’t work in postman either? If it were me, I’d work out the plumbing there first rather than code. I’m sure you know this, but this is what a good call in Postman looks like:
When you use a valid Epicor account and enter it that way, are you still getting a 401?
Also, this is a long shot, but I had an issue long ago where I’d use an account to authenticate with and it would work like 3 times, then it wouldn’t. It would lock the account in Epicor and I had to reset the password.
If your account password is expiring, it would probably throw a 401. I have some instructions on how to fix if you need to go down that path