I would like to access the API (https://vrmapi.victronenergy.com/v2/auth/login) from a C# application, but gets a server error 401. Any example avialable?
This site is now in read-only archive mode. Please move all discussion, and create a new account at the new Victron Community site.
I would like to access the API (https://vrmapi.victronenergy.com/v2/auth/login) from a C# application, but gets a server error 401. Any example avialable?
Hey, perhaps if you provide C# code I could help you adjust it.
What you need to do according to the documentation, and which works for me, is:
1. Send a POST request to https://vrmapi.victronenergy.com/v2/auth/login with a a payload {"username":"your_user", "password":"your_pass"}
2. Receive back {"idUser":12345, "token": "random_token_characters"}
3. Include the token that you've received in as a header with every consequent request, for example https://vrmapi.victronenergy.com/v2/users/12345/installations, as follows
X-Authorization:"Bearer random_token_characters"
Regards,
Nik
Hi Nik,
Hereby the C# code - thanks in advance :-)
url = "https://vrmapi.victronenergy.com/v2/auth/login/";
var client = new WebClient();
var method = "POST";
var parameters = new NameValueCollection();
parameters.Add("username", usernameVictron);
parameters.Add("password", passwordVictron);
var response_data = client.UploadValues(url, method, parameters);
var responseString = UnicodeEncoding.UTF8.GetString(data);
Hey Lars,
This code actually looks correct (although I can't test it right now).
In such a case my best guess for the 401 is that the user and/or pass are incorrect/invalid.
Perhaps test it in some other way. Postman is a really nice tool for dealing with APIs https://www.getpostman.com There's a browser extension for it as well. I guess just lookup some quick tutorial.
Or if you fancy the command line try curl or httpie, etc.
Regards,
Nik
Hi Guys,
Im a Newby, Just got my Victron setup with the venus gx and now wanting to use the API to add data to my IOT home assistance dashboard .
Im using postman to test but all i get is :
{
"success": false,
"errors": "Invalid credentials",
"error_code": "invalid_credentials"
}
Posting to : https://vrmapi.victronenergy.com/v2/auth/login
{"username":"xxxxxx@xxxx.com", "password":"abcdef"}
"the username and password is correct as i tested it on the portal"
what am i doing wrong?
Regards
Same error here; I've got 401 "Invalid credentials". i've tried with postman and curl...
In case it helps someone
A C# program to login to the API
Just replace the username and password variableProgram.txt
Additional resources still need to be added for this topic
9 People are following this question.