Call Api C#

Mick Vazovsky

New Member
Feb 10, 2021
9
0
1
42
Help me figure it out, the token is there, the call does not accept the header.

Безымянный.png

C:
using (var client = new HttpClient())
            {
                var url = "https://10.40.100.95:8006/api2/json/nodes";
                client.DefaultRequestHeaders.Add("Authorization", "PVEAPIToken=test@pve!TOKENID=ddf5959760540181d171d2e2a7adcba4");
                var response = await client.GetStringAsync(url);
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Include
                };


                dynamic stuff = JsonConvert.DeserializeObject(response, settings);
                Console.WriteLine(stuff);
                Console.ReadLine();
            }

FormatException: The format of value 'PVEAPIToken=test@pve!TOKENID=ddf5959760540181d171d2e2a7adcba4' is invalid.
 
Last edited:
Hey,

TOKENID has to be the token id.
1612951132516.png
 
Fixed, but the error is the same.

Безымянный.png

FormatException: The format of value 'PVEAPIToken=test@pve!TOKENID=ddf5959760540181d171d2e2a7adcba4' is invalid.
 
...@pve!TOKENID=ddf59...
this has to be the token id and after the '=' the secret thing has to follow, the one that was displayed when you created the API token.
 
...@pve!TOKENID=ddf59...
this has to be the token id and after the '=' the secret thing has to follow, the one that was displayed when you created the API token.
Not understand, how to write?:

user name:
test@pve

token name and password:
ddf5959760540181d171d2e2a7adcba4

tokenID:
test@pve!ddf5959760540181d171d2e2a7adcba4

Secret:
ad78e07e-a418-41a1-a201-3528154737f2


client.DefaultRequestHeaders.Add("Authorization", "PVEAPIToken=test@pve!ddf5959760540181d171d2e2a7adcba4=ad78e07e-a418-41a1-a201-3528154737f2"); ???
 
Is it possible that this error message comes from the C# program, and not from the API?
 
Maybe take a look at https://github.com/ionelanton/ProxmoxSharp, the problem is in your program, not the API endpoint.

I succeeded, I used a call with RestSharp
Thanks Hannes for your help )).


C:
var client = new RestClient("https://10.40.100.95:8006/api2/json/nodes");
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("Authorization", "PVEAPIToken=test@pve!ddf5959760540181d171d2e2a7adcba4=ad78e07e-a418-41a1-a201-3528154737f2");
            IRestResponse response = client.Execute(request);

            var settings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Include
            };

            dynamic stuff = JsonConvert.DeserializeObject(response.Content, settings);
            Console.WriteLine(stuff);
            Console.ReadLine();
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!