VMware Cloud Community
Phil_K
Enthusiast
Enthusiast
Jump to solution

vROPS REST API Java Sample

Can anyone help me get a clear sample of how to instantiate the client and run a basic get command with Java?

I see from the documentation it's recommended to use something like:

Client client =

        ClientConfig.builder()

                .serverUrl("https://{ip}/suite-api/")

                .basicAuth("username", "password")

                .useJson()

                .build();

System.out.println(client.platformMetadatas().listAdapterTypes());

but how do I build off of this for a get command, say get all adapters? For one, the platformMetadatas class isn't recognized so they don't even provide a good example.

I understand I should just go learn Java and then it will all make sense eventually, but the documentation didn't seem very clear to me.

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
PluRav
Enthusiast
Enthusiast
Jump to solution

Hello

 

To get all adapter instances you could try something like this:


Client client = ClientConfig.builder().serverUrl("https://{ip}/suite-api")

    .basicAuth("user", "pass")

    .userJson()

    .build()

    .newClient();


AdapterInstancesInfoDto adapters = client.adapterInstancesClient().list();

 

Basically, after you get the client running, you can get different 'subclients' from it like adapterInstancesClient above.

Hope this helps

 

        Client client = ClientConfig.builder().serverUrl("https://localhost/suite-api")
                .basicAuth(restUser, restPass)
                .build()
                .newClient();
        
        AdapterInstancesInfoDto adapters = client.adapterInstancesClient().list();
        
        for (AdapterInstanceInfoDto adapter : adapters.getAdapterInstancesInfoDto()) {
            System.out.println(adapter);
        }

View solution in original post

Reply
0 Kudos
2 Replies
PluRav
Enthusiast
Enthusiast
Jump to solution

Hello

 

To get all adapter instances you could try something like this:


Client client = ClientConfig.builder().serverUrl("https://{ip}/suite-api")

    .basicAuth("user", "pass")

    .userJson()

    .build()

    .newClient();


AdapterInstancesInfoDto adapters = client.adapterInstancesClient().list();

 

Basically, after you get the client running, you can get different 'subclients' from it like adapterInstancesClient above.

Hope this helps

 

        Client client = ClientConfig.builder().serverUrl("https://localhost/suite-api")
                .basicAuth(restUser, restPass)
                .build()
                .newClient();
        
        AdapterInstancesInfoDto adapters = client.adapterInstancesClient().list();
        
        for (AdapterInstanceInfoDto adapter : adapters.getAdapterInstancesInfoDto()) {
            System.out.println(adapter);
        }
Reply
0 Kudos
Phil_K
Enthusiast
Enthusiast
Jump to solution

Hello,

The code throws no errors, and I do believe it is correct. There is one minor issue, and maybe you could help? I get an error 404; invoking handler error. I must not have all the appropriate packages listed at the top of my code.

When I figure that out I'm sure this will work. Do you know, will the java command line prompt for the password if I leave it out of the code?

Reply
0 Kudos