VMware {code} Community
mlawson
Enthusiast
Enthusiast

get all Vapp Templates in catalog

using the .net sdk...

How do you get all VappTemplates in a specific catalog?

I am able to successfully retrieve them all using vdc.GetVappTemplateRefs() but that doesn't let you specify or filter on a catalog.

is there a method to retrieve template refs by catalog or is there a way to filter the list i get using vdc.getVappTemplateRefs() ?

thanks in advance.

0 Kudos
2 Replies
rkamal
VMware Employee
VMware Employee

Hi,

You can use the query service and filter the results.

Using the VappTemplate query you can filter the results based on the catalog name. Below is an API & Java SDK example. You can easily convert the java sample to C#.

REST API:

     Ex: https://vcloud/api/query?type=adminVAppTemplate&filter=(catalogName==mycatalog)&format=records

Java SDK:

      QueryParams<QueryAdminVAppTemplateField> queryParams = new QueryParams<QueryAdminVAppTemplateField>();
      queryParams.setFilter(new Filter(new Expression(QueryAdminVAppTemplateField.CATALOGNAME, "mycatalog", ExpressionType.EQUALS)));
      RecordResult<QueryResultAdminVAppTemplateRecordType> vappTemplateResult = client.getQueryService().queryRecords(
                                                                                                                                     QueryRecordType.ADMINVAPPTEMPLATE, queryParams);
      for (QueryResultAdminVAppTemplateRecordType vappTemplateRecord : vappTemplateResult.getRecords()) {
         System.out.println(vappTemplateRecord.getName());
      }
Regards,
Rajesh Kamal.
mlawson
Enthusiast
Enthusiast

thanks for your help... for anyone looking to do this with the c# SDK here's my code:

QueryParams<QueryVAppTemplateField> queryParams = new QueryParams<QueryVAppTemplateField>();
queryParams.Filter = new Filter(new Expression(QueryAdminVAppTemplateField.CATALOGNAME, "myCatalog", ExpressionType.EQUALS));
RecordResult<QueryResultVAppTemplateRecordType> vappTemplateResult = client.GetQueryService().QueryRecords<QueryVAppTemplateField, QueryResultVAppTemplateRecordType>(QueryRecordType.VAPPTEMPLATE, queryParams);
foreach (QueryResultVAppTemplateRecordType record in vappTemplateResult.GetRecords())
{
    // do stuff...
}
0 Kudos