VMware Cloud Community
dbis7575
Enthusiast
Enthusiast
Jump to solution

vRA8 update Tags with API call

I am trying to update Tags on a machine that is part of a deployment using the following API call:

/deployment/api/deployments/{depId}/resources/{resourceId}/requests

With the following body:

{
 
"actionId": "Cloud.vSphere.Machine.Update.Tags",
 
"inputs": {

                         "key":"testkey"

                         "value":"testvalue"  

                 },
 
"reason": "testing"
}

When I run this the response shows the task is not completed and pending, when looking at the GUI it completes without updating the tags.

I expect the issue is with the inputs being provided, I have tried different variations most of them that result in an error. If I place a tag on the machine prior to running this API call, the tag gets removed (assume I have to read them in and pass them back with the update call).

If anyone has this functional, please provide the correct syntax.

Reply
0 Kudos
1 Solution

Accepted Solutions
stevedrummond
Hot Shot
Hot Shot
Jump to solution

Your input needs to be an array of tags including the existing tags you want to keep.

"inputs": {

     "tags": [

          { "key":"myTag", "value": "myValue" },

          { "key":"anotherTag", "value":"anotherValue" }

     ]

}

View solution in original post

Reply
0 Kudos
8 Replies
stevedrummond
Hot Shot
Hot Shot
Jump to solution

Your input needs to be an array of tags including the existing tags you want to keep.

"inputs": {

     "tags": [

          { "key":"myTag", "value": "myValue" },

          { "key":"anotherTag", "value":"anotherValue" }

     ]

}

Reply
0 Kudos
dbis7575
Enthusiast
Enthusiast
Jump to solution

Steve,


That did it, thank you very much.

Reply
0 Kudos
KDUGanesh
Contributor
Contributor
Jump to solution

where to update the code, is it in cloud template, need more details

Reply
0 Kudos
gregd90
Enthusiast
Enthusiast
Jump to solution

This is an API call from Postman etc. to the vRA API. It's executed against a machine in a deployment. Consider it as a Day 2 operation on the machine.

The Cloud Template contains the constraint tags read at request phase, in this scenario they are not updated.

Regards,

Greg, VMware

vinaykumar561
Contributor
Contributor
Jump to solution

Hi Steve,

I have similar task to do, but in this case API call is triggering day2 with actionID but in my case I don't have "Update Tags" day2 resource action. I need actual workflow code to update tags. could you please help me with that?.

Many Thanks in Advance

Tags (1)
Reply
0 Kudos
Shafiya
Contributor
Contributor
Jump to solution

Hi Team, May I know the reason why VRA supports only POST api for adding/updating/deleting the tags?
Is there any endpoint which support only these requests separately
PUT/POST -> for posting or updating the tags alone
DELETE -> for deleting the tags.

Because the problem with current api  (/deployment/api/deployments/{depId}/resources/{resourceId}/requests) is we have to pass all the existing tags as well which wont be possible in my scenario as I will be calling VRA resources api to fetch the latest resources once in every hour. so in between this time if I perform multiple tags api calls with different data then I will be losing the tags posted earlier ryt?

Scenario Explanation:
resource1 -> has tags (tag1:val1, tag2:val2) -> in my code I have called the api to fetch the resources (now I wont be calling this api again for next one hour).
and from the code if I perform 2 tagging api calls 
 - 1st tag apicall with tag1:val1, tag2:val2updated, tag3:val3, in this case resource1 in VRA will be updated with these 3 tags
 - 2nd tag apicall with tag1:val1, tag2:val2, tag4:val4, in this case resource1 in VRA will be updated with these 3 tags

so I will be losing the tag2 updated value and tag3 as this api will be deleting all the missing tags, also as the resource is not updated yet I am getting old tag2 value only.
so this is the reason I am wondering why VRA is not handling these requests separately?? Kindly someone please let me know the reason behind it??
Also please share this api documentation for the rest api so that it will be really helpful

Reply
0 Kudos
Shafiya
Contributor
Contributor
Jump to solution

Hi Team
In VCenter console I am able to see Tags option for switches resources, but when I try attaching a tag, It is giving operation failed message. 
I have tried adding category with all the associable types mentioned below, added a new tag and tried to attach it to switches resource,
Associable Types Attached while creating category:
["ClusterComputeResource","DistributedVirtualSwitch","VmwareDistributedVirtualSwitch","com.vmware.content.library.Item","ResourcePool","Folder","HostNetwork","DistributedVirtualPortgroup","VirtualApp","StoragePod","Datastore","Network","Datacenter","com.vmware.content.Library","HostSystem","OpaqueNetwork","VirtualMachine"]

Also I have tried attaching tag using Endpoint. But I am getting 403 response.
https://{vcenter_url}/rest/com/vmware/cis/tagging/tag-association?~action=attach-multiple-tags-to-ob... 403 Forbidden
Error: cloudadmin does not have attach privilege on DynamicID

Can someone please help me with the documentation on attaching tags to switches resources?
If tagging is possible for switches resource or not? If possible what are the permissions required for attaching tags to switches resources.

Thanks in Advance.

Reply
0 Kudos