Invoke-RestMethod : 401: Unauthorized
Closed this issue · 2 comments
Hi there
first of all many thanks for this nice piece of software. I tried to get it working but get the below error.
steps to reproduce
- create long-living token in HA
- download the code and copy to C:\Scripts
- add variables in GetTeams-Status
- execute install-script
this is how my variables in GetTeams-Status look like, I changed them because initially I got some errors and asked Chat GPT how to format it correctly (hopefully) ;)
Some variables
${HAToken} = $env:eyJhbGXXX...
${HAUrl} = "http://192.168.1.46:8123"
${appDataFolder} = GetAppDataFolder
${userName} = GetUserName
I executed the install-script and get the below error.
Invoke-RestMethod : 401: Unauthorized
In C:\Scripts\TSFunctions.ps1:21 Zeichen:5
-
Invoke-RestMethod -Uri "$HAUrl/api/states/$entityId" -Method POST ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption - FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Invoke-RestMethod : 401: Unauthorized
In C:\Scripts\TSFunctions.ps1:21 Zeichen:5
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
-
Invoke-RestMethod -Uri "$HAUrl/api/states/$entityId" -Method POST ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption - FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
environment
Microsoft Surface Pro 9 with Windows 11 Pro and a local user called grafm. I am logging in with a corporate-account in Teams.
I kindly appreciate any help to get it working
all the best
Andrew
I stopped supporting the configuration file in favor for the environment variables.
It would be easiest to revert the files to their original states and then create the environment variables.
The error you get seems like an authentication problem so this might resolve it if the credentials are not making it properly.
I understand, I will try to figure it out and close this issue for now