v3 - Error 403 api/nutanix/v3/vms/list | Nutanix Community
Skip to main content
Hello All,



I can not list the VMs with the v3 version, I have the same error with the API explorer, I have an error 403, my cluster is in version 5.5.3.1 can you help me?



Code:

code:
$username = 'admin';
$password = "pass";
$url2 = "https://a01ntnx003:9440/api/nutanix/v3/vms/list";
$data_string2 = '{\"kind\":\"vm\"}';
$ch2 = curl_init($url2);
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch2, CURLOPT_POSTFIELDS, $data_string2);
curl_setopt($ch2, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch2, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, false);
$data3 = curl_exec($ch2);




Error:

code:
{ "state": "ERROR", "code": 403, "message_list": [ { "message": "Requested action is not supported.", "reason": "ACTION_NOT_SUPPORTED" } ], "api_version": "3.0" }
Hi



Read the following articles:-



https://developer.nutanix.com/2019/01/15/nutanix-api-versions-what-are-they-and-what-does-each-one-do/?fbclid=IwAR2Qt7soRYx4W1wAlITLNQ_aUxhe7EYkcTgfgKt9LDJEfULWXIbOCM6Q_A0



https://portal.nutanix.com/#/page/docs/details?targetId=API-Ref-AOS-v58:man-rest-api-c.html
Even though the Documentation lists "Optional" for Length, you still have to have a valid value there for it in the body. Change your body to add the length value.

code:
{
"kind": "vm",
"length": 100
}

I send you part of my code, Nutanix API asks for the offset and the length, if you do not place them, I will give you the information with a maximum of 500 entities. For that you must page the data.


I ran into a similar issue. One thing that I found is make sure that you send the Content-Type: application/json header with your POST requests. I also found that I had to send at least an empty JSON object in the body of the POST request. Though as others have said, if you don't give a length attribute you may not get back all of the objects you're searching for. I haven't run into an issue with omitting the kind key though. In my case omitting the length key, I get back 20 out of 35 VMs. Hope this helps.