Solved

How assign a category to a vm within REST API Prism Central

  • 19 October 2021
  • 2 replies
  • 704 views

Hello

I would like to use REST API within Prism Central to assign a category to a VM.

I dont know how to do that

Do I need to use this API 

- “Update an existing VM” (put /vms/{uuid})

or this API

- “Create or Update a category value” (put /categories/{name}/{value})


And how can I use it to assign a new category and not remove previous category ?

Regards

Pascal

 

 

 

icon

Best answer by PascalM 19 October 2021, 09:32

View original

This topic has been closed for comments

2 replies

Ahhh finally I answer to myself :-)

I have to use  “Update an existing VM” (put /vms/{uuid})

and the difficulty for me was to understand what I need to pass for the request payload/body

I need to specify a JSON with the current SPEC of the VM + the metadata with category list

{
  "spec": {
      < every thing of current vm >
  },
  "metadata": {
    "kind": "vm"
    "uuid": <VM UUID>,
    "spec_version": 3,
    "categories_mapping": {
      "ABC1": [
        "abc_1_1"
      ],
      "TEST2": [
        "test1"
      ]
    },
    "categories": {
      "ABC1": "abc_1_1",
      "TEST2": "test1"
    }
  }
}

 

Not so easy to do but it was ok at the end

Regards

Userlevel 4
Badge +5

Good to heard you found what you were looking for. In case you want to know more about Nutanix APIs and get familiar on how to use them, you have several blog posts in our Nutanix.dev website.