Solved

Nutanix API v2

  • 5 January 2021
  • 17 replies
  • 1876 views

Userlevel 1
Badge

Hi! I've got several questions about the usage of v2 API which I have not been able to solve by myself after looking a little while.

on some endpoints, for example, GET /alerts, GET /vms and a few more things are functioning for me as expected, but on other endpoints, such as 
POST /vms/{uuid}/set_power_state I am receiving the following response:

{
"message": "Access is denied",
"detailed_message": null,
"error_code": {
"code": 1100,
"help_url": "http://my.nutanix.com"
}
}
  • any idea what's causing it?
  • I've been searching for detailed information on your error code (such as 1100 listed above) and couldn’t find. Is there any documentation to the error codes that  you can send me a link to?


Also, in a few of the API endpoints I couldn’t understand exactly what is the expected query parameter to be sent.
2 examples of endpoints I felt I am lacking knowledge what exactly meant to be sent

  • GET /vms
    • filter: Filter criteria - semicolon for AND, comma for OR. where can I find what counts as filter criteria?
  • POST /alerts/acknowledge
    • classification - unsure which classifications can be sent
    • same goes for entity_type

Is there another place which has a more detailed explanation about query parameters other than https://www.nutanix.dev/reference/prism_element/v2/api ?

Thanks in advance!

icon

Best answer by Tomer-M 5 January 2021, 17:59

View original

This topic has been closed for comments

17 replies

Userlevel 6
Badge +5

Hey @Tomer-M . Happy new year mate.

So as far as I know the HTTP error code of 1100 means Missing parameter. Here is an online article which I found says the same: https://developer.betterdoctor.com/error-codes

Are you sure when executing API POST /vms/{uuid}/set_power_state , you are entering all the required parameters?

I think the only param this API requires is the VMs UUID as per https://www.nutanix.dev/reference/prism_element/v2/api/vms/post-vms-uuid-set-power-state-setpowerstate/

And regarding the documentation of REST APIs, we only have this https://www.nutanix.dev/reference/prism_element/v2/api/ documentation for APIs, but let me get back to you with some detailed answer about the parameters required for those 2 API endpoints after implementing the same. :sweat_smile:

Userlevel 1
Badge

Thanks a lot Anish!

about - 
Are you sure when executing API POST /vms/{uuid}/set_power_state , you are entering all the required parameters?

quite sure, I did a GET /vms ,
took “uuid” field I got from one of the vms there.

also, I've been getting access denied on API call that doesn’t require any parameter, such as
POST alerts/acknowledge https://www.nutanix.dev/reference/prism_element/v2/api/alerts/post-alerts-acknowledge-acknowledgealerts/
POST alerts/resolve
https://www.nutanix.dev/reference/prism_element/v2/api/alerts/post-alerts-resolve-resolvealerts/

Userlevel 6
Badge +5

Hey @Tomer-M , thanks for the udpate. Let me research more on this error and get back as soon as I find anything.:smiley:

Userlevel 1
Badge

I was using a username for authentication and the user did not have permissions to do such actions, that’s why I was getting the access denied message, my bad.
Thanks!

Userlevel 6
Badge +5

Ahh I see, that makes sense @Tomer-M , glad it worked out.:smile:

Userlevel 1
Badge

Awesome.

If you could still somehow figure what are the possibilities for filters for get /vms and get /hosts it would be great, as for some filters I'm getting
"message": "Exception while retrieving entities : java.lang.RuntimeException: Unrecognized field X passed, unable to build filter.",
and for other filters it seems to be functioning as expected.
Thanks!

Userlevel 6
Badge +5

hey @Tomer-M , sure I will get back to you on this after researching on this.:smile:

 

Yes this error message is expected “"message": "Exception while retrieving entities : java.lang.RuntimeException: Unrecognized field X passed, unable to build filter.",” when wrong parameters are passed.

Userlevel 6
Badge +5

Hey @Tomer-M , So I did a little research on the Filter parameter for the  GET /vms and GET /hosts v2 API.

Unfortunately, filters are officially not supported. Therefore any filters would be unsupported/undocumented.

Now it does not mean they don’t work. It’s just that you have to figure out which params are supported by trying them out.

I will tell you what I do is I usually do a simple GET of the object, examine it that helps me figure out what POST syntax works

Then try filtering on some of its params to see which ones work. Unfortunately, we don’t have any documentation for this. Hopefully, REST API v4 is better documented. 

I hope this helps.

Userlevel 1
Badge

Thanks a lot! it does help.
Last question if I may,
I also have troubles figuring what is the entity_type_ids for endpoints
https://www.nutanix.dev/reference/prism_element/v2/api/alerts/post-alerts-resolve-resolvealerts/
https://www.nutanix.dev/reference/prism_element/v2/api/alerts/post-alerts-acknowledge-acknowledgealerts
I’ve been doing GET /alerts and tried using the field ‘id’ in ‘affected_entities’ received from GET /alerts response, but it doesn’t seem to have any effect at all. could it be that entity_type_ids isn’t supported? or did I sent the wrong parameter to it?

Userlevel 6
Badge +5

Hey @Tomer-M , it’s indeed a pleasure. :smile:

So below is the JSON of a sample alert:
 

{
"id": "ac4008c3-dcf6-4f82-980f-c68bad80ee1a",
"alert_type_uuid": "A200601",
"check_id": "000582c6-cf0d-e0a8-0000-000000016950::200601",
"resolved": true,
"auto_resolved": true,
"acknowledged": true,
"service_vmid": "000582c6-cf0d-e0a8-0000-000000016950::13",
"node_uuid": "13",
"created_time_stamp_in_usecs": 1608546739938508,
"last_occurrence_time_stamp_in_usecs": 1608548897301418,
"cluster_uuid": "000582c6-cf0d-e0a8-0000-000000016950",
"originating_cluster_uuid": "000582c6-cf0d-e0a8-0000-000000016950",
"severity": "kWarning",
"impact_types": [
"Configuration"
],
"classifications": [
"Network"
],
"acknowledged_by_username": "N/A",
"message": "Flow policy operation failed for {rule_name}. {reason}",
"detailed_message": "",
"alert_title": "Flow rule: {rule_name} Failed",
"operation_type": "kCreate",
"acknowledged_time_stamp_in_usecs": 1608722540281611,
"resolved_time_stamp_in_usecs": 1608722540281605,
"resolved_by_username": "N/A",
"user_defined": false,
"affected_entities": [
{
"entity_type": "cluster",
"entity_type_display_name": null,
"entity_name": null,
"uuid": "000582c6-cf0d-e0a8-0000-000000016950",
"id": "92496"
}
],
"context_types": [
"network_security_rule_uuid",
"rule_name",
"rule_type",
"reason",
"arithmos_id",
"ncc_version",
"nos_version",
"cluster_id",
"cluster_uuid"
],
"context_values": [
"0152093e-2591-4642-98a3-3fd4e9b7f183",
"Quarantine",
"3",
"Rule update from PE to AHV host 90e6c004-3394-4f9a-940a-b5ead752bccb failed, retrying...",
"92496",
"3.10.1-13b6fdc2",
"5.18.1.1",
"92496",
"000582c6-cf0d-e0a8-0000-000000016950"
],
"possible_causes": [],
"alert_details": null
},

 

In the above do you notice :
affected_entities": [
        {
          "entity_type": "cluster",
          "entity_type_display_name": null,
          "entity_name": null,
          "uuid": "000582c6-cf0d-e0a8-0000-000000016950",
          "id": "92496"
        }

]

I think this is what “affected_entities” is an array of above params. And “entity_type” here is a string “cluster” and I think It can be “host”,”vm” etc type of entities, and as per above the “entity_type_ids” would be the id value “92496”(here it is the cluster ID).

Userlevel 1
Badge

Thanks Anish! I really appreciate your help.
This does confuse me a bit with this https://www.nutanix.dev/reference/prism_element/v2/api/alerts/get-alerts-getalerts/ what is entity_ids then? if I wrote the id value for entity_ids query param in this request, it seemed to have no effect. is it supposed to be other field? thanks a lot!

Userlevel 6
Badge +5

Hey @Tomer-M , it is indeed a pleasure to help mate. :smile:

I think the parameter “entity_id” is supposed to be the IDs of the entity, are you sure you are entering the ID of the entity or it’s UUID ?

Also it is an array of string, did you use the right format ?

Userlevel 1
Badge

Hi Anish, it is a pleasure receiving such polite and great answers from you. appreciate it
well, for entity_ids 
 

affected_entities": [
        {
          "entity_type": "cluster",
          "entity_type_display_name": null,
          "entity_name": null,
          "uuid": "000582c6-cf0d-e0a8-0000-000000016950",
          "id": "92496"
        }

]
I've tried inserting both the “uuid” and “id” fields mentioned here for my alerts, but it did not have any effect (other alerts with different id or uuid fields were not filtered)
 

Userlevel 6
Badge +5

Hey @Tomer-M ,thanks a lot buddy for such kind words, really appreciate them.:smile:  

It is always a pleasure to help.

 

So let me research about this param more and get back to you soon. 

Userlevel 1
Badge

Thanks a lot @AnishWalia20, I’ll be waiting for your response. thanks!

Userlevel 6
Badge +5

Hey @Tomer-M , so I researched a bit on it.

So basically the parameter “entity_ids” could most likely be the list of UUIDs of the alerts you want to get? I’m just guessing since you mentioned it doesn’t work or show anything differently with the entity ids of VMs, cluster, host etc.

Within the REST API, the entity usually designates a returned object, so it could be anything.

Since this is a GET method, this is a list of things you get, not one you specify like in a POST method.

In POST HTTP method you can send a payload by specifiying a parameter, but not in GET. Just try a normal GET request on this endpoint  https://www.nutanix.dev/reference/prism_element/v2/api/alerts/get-alerts-getalerts/ and see what it returns in the “entity_Ids” and see where it matches.

Hope it helps

Userlevel 7
Badge +34

Hi @Tomer-M 

If any of these answers help, please mark one of them as ‘Best Answer’. This will help others in the community find the same content much faster. Thanks for contributing to the community.