Error:"enableUnautorized"

Hi, I'm trying to connect a windows 11 laptop to an enviroment that I created, for some reason zrok returns an error [POST /enable][401] enableUnauthorized. I tryied to change the apiEndpoint but it changes nothing.

Hi there! :wave: Are you self-hosting your own zrok instance? If so, you need to run that set apiEndpoint command to tell your local zrok.exe command to use your instance. The value of <newEndpoint> will be something like https://some.zrok.io.

In case you're not self-hosting your own zrok instance, then the problem is likely an incorrect account token (the one that's redacted), because zrok enable ACCOUNT_TOKEN is the correct command, substituting your token, of course.

Your account token can be found in the zrok web console where the profile drop down menu says "enable your environment" or the "detail" tab of your account where it says "token."

Hi, I'm self hosting and already run set apiEndpoint.

I think the config set apiEndpoint command did not work because your zrok.exe still thinks it should be talking to https://api.zrok.io (the default instance from NetFoundry).

You can see the current configuration by running:

C:\> zrok status

Yes, zrok is talking to https://api.zrok.io how I see what instance should I be using?

You can configure your Windows environment by running this command:

C:\> zrok config set apiEndpoint https://zrok.example.com

...substituting your self-hosted zrok controller's URL for https://zrok.example.com.

So, if you have a Linux VPS with a public IP where you installed zrok controller, and you made a wildcard DNS record like *.example.com for your VPS's public IP, then you probably have an nginx or caddy HTTP route for your controller like zrok.example.com zrok-controller:18080.

Are you following one of the self-hosting guides, like for Linux, Docker, or Kubernetes?

https://docs.zrok.io/docs/category/self-hosting/

I'm sorry but I misunderstood the self hosting thing and I'm not self hosting, I'm dumb.
So, I know the token is correct, what could be the problem?

There are two similar-looking tokens that you might have mixed up: registration token and account token.

You need the account token from the zrok web console in https://api.zrok.io

If you're able to log in there and pull down the menu at top-right where it says "Enable your environment," that is the correct token.

If you're already using that token it could be a strange copy/paste or text encoding issue, or maybe one of the characters got dropped along the way.

Are you placing the account token on your clipboard then right-clicking in the Windows terminal to paste?

If all else fails, especially if your Windows environment is the first one you tried to enable, you can rotate your account token to get another one like this:

I regenerated my account token and when I went to the '${HOME}/.zrok/environment.json' for updating the files I didn't find the 'enviroment.json' file.

Are you using Powershell or CMD prompt for your Windows terminal? We'll need to translate the UNIX ${HOME} to something the Windows terminal understands.

I did not use the command, I went to the folder and the file wasn't there.

OK, cool. That means the zrok enable command never succeeded and you don't need to manually edit %USERPROFILE%\.zrok\environment.json.

You're using NetFoundry's default zrok instance, so you don't need to run the zrok config set command we discussed earlier since that's only for self-hosters with a custom instance.

I think we're ready to try again with your regenerated zrok account token.

C:\> zrok enable ACCOUNT_TOKEN_HERE

It returns the same error even with the new token, in my main pc now it won't connect to the eviroment and has the same error.

ok I re-re generated the token now it function!! Thanks for the help!

Oh good! Yay.

For the next person, another thing that can cause this problem is too many environments. Each hosted zrok.io plan has limits on the number of environments, so you might need to clean up one to make a new one.

Have fun and let us know if you get stuck again.