VMware Cloud Community
qc4vmware
Virtuoso
Virtuoso
Jump to solution

vAPI list all tagged objects doesn't seem to work. Anyone accomplished this via the vAPI plugin successfully?

I'm trying to make sense of the vAPI plugin and also reading through the online documentation and I haven't seen any examples of listing tagged objects.  If I access the rest api directly and look at the resource definitions for com/vmware/vapi/rest/navigation/resource/id:com.vmware.cis.tagging.Tag I see this which sounds like what I need:


{

      "name": "list_attached_objects",

      "documentation": "Fetches the {@term list} of attached objects for the given tag. To invoke this {@term operation}, you need the read privilege on the input tag. Only those objects for which you have read privileges will be returned.",

      "service": "com.vmware.cis.tagging.tag_association",

      "links": [

        {

          "method": "POST",

          "href": "https://server.example.com/rest/com/vmware/cis/tagging/tag-association/id:{tag_id}?~action=list-attached-objects"

        }

      ],

      "metadata": {

        "method": "GET",

        "href": "https://server.example.com/rest/com/vmware/vapi/metadata/metamodel/service/operation/id:com.vmware.cis.tagging.tag_association/id:list_attached_objects"

      }

    }

When I attempt to run this I get an error from the api as follows:

{

  "name": "com.vmware.vapi.rest.httpNotFound",

  "localizableMessages": [

    {

      "defaultMessage": "Not found.",

      "id": "com.vmware.vapi.rest.httpNotFound"

    }

  ],

  "majorErrorCode": 404

}

Does anyone here know this api well enough to tell me if I am making the correct call and if so can you verify that it is working?  eternallyfrustratedbyVMware‌ how's that for a tag? hopeIJustNeededToRTFM‌ Smiley Happy

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

How did you run it? Using HTTP-REST plug-in?

vAPI plug-in doesn't communicate with vAPI endpoint via REST. You need to use vAPI script objects automatically generated when you imported vAPI metamodel.

You can look at 'List all tags' sample workflow that comes with vAPI plug-in and modify it. The scripting code would look something like the following (endpoint and tagid are input parameters)

if (endpoint == null) {

  throw "'endpoint' parameter should not be null";

}

var client = endpoint.client();

var tagging = new com_vmware_cis_tagging_tag__association(client);

var result = tagging.list_attached_objects(tagid);

System.log(result);

View solution in original post

6 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

How did you run it? Using HTTP-REST plug-in?

vAPI plug-in doesn't communicate with vAPI endpoint via REST. You need to use vAPI script objects automatically generated when you imported vAPI metamodel.

You can look at 'List all tags' sample workflow that comes with vAPI plug-in and modify it. The scripting code would look something like the following (endpoint and tagid are input parameters)

if (endpoint == null) {

  throw "'endpoint' parameter should not be null";

}

var client = endpoint.client();

var tagging = new com_vmware_cis_tagging_tag__association(client);

var result = tagging.list_attached_objects(tagid);

System.log(result);

mvaleva
VMware Employee
VMware Employee
Jump to solution

If you want to use the vAPI plug-in, then the answer is the one given by Ilian.

If you want to use the REST api, then you need to:

1. Log into the vAPI endpoint by using a REST client (or vRO HTTP-REST plug-in):

HTTP method: GET

URL: https://server.example.com/rest/com/vmware/cis/session?~method=post

2. List tag associations by:

HTTP method: POST

URL: https://server.example.com/rest/com/vmware/cis/tagging/tag-association/id:{tag_id}?~action=list-atta...

You will get NotFound exception if you use GET method instead of POST method.

qc4vmware
Virtuoso
Virtuoso
Jump to solution

Thanks!  That worked like a charm.  Since the scriptable objects weren't showing up in my api explorer I was struggling with what to call.  Now the api explorer is showing all of the objects so hopefully I can muddle through anything else I need to do.  I'll update my other post related to the api explorer.  I really appreciate the help!

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso
Jump to solution

I must have missed that I needed to do a post.  Yes that worked just fine when I used the correct request!  Thank you for your assistance!

Reply
0 Kudos
HXTB5
Contributor
Contributor
Jump to solution

Hi, i am trying to take a backup to my vcenter server but i am facing a trouble with the following

{"type":"com.vmware.vapi.std.errors.unauthenticated","value":{"messages":[{"args":[],"default_message":"Authentication required.","id":"com.vmware.vapi.endpoint.method.authentication.required"}]}}Backup job id:

i think it is an issue related to API but i don't have an idea about manage them

could please help me to solve this issue

thanks

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi HXTB5

Which vAPI plug-in version/build number do you use? This error looks similar to an issue we had at some point and which is supposedly fixed in the current plug-in builds, so I would recommend to try with the latest technical preview build of the plug-in available here - https://communities.vmware.com/docs/DOC-35527

Reply
0 Kudos