Get app details from Java

The Marketplace API Java client lets you get information about an app through the Addons API.

For a stand-alone demo, see GetAddon.java in the Marketplace API Tutorials repository.

Prerequisites

You will need:

  • A Java project that uses the marketplace-client-java library
  • The app key of an existing app listing on Marketplace
  • MarketplaceClient object

Query a public app

The getByKey method of the Addons API queries the details of an app given its app key. It returns an Option containing an Addon object, or Option.none() if the app key was not found:

1
2
Option<Addon> result = client.addons().getByKey("my.excellent.app", AddonQuery.any());
// Option implements Iterable, so we can use "for" to execute this code only if it has a value    
for (Addon a: result) {
    System.out.println("I found the app; its name is " + a.getName());
}
if (!result.isDefined()) {
    System.out.println("not found");
}

Include version data

Remember that we specified the default option (AddonQuery.any()) in the example above. One way to vary the query is to ask for the current app version at the same time:

1
2
AddonQuery query = AddonQuery.builder().
    withVersion(true).
    build();
Option<Addon> result = client.addons().getByKey("my.excellent.app", query);
for (Addon a: result) {
    System.out.println("I found the app; its name is " + a.getName());
    for (AddonVersion v: a.getVersion()) {
        System.out.println("And the latest version is " + v.getName());
    }
}

If you specify any other criteria in the AddonQuery, you will get the latest app version that matches those criteria. If there is no such version, the query will return nothing (not even the app). In this example, we are asking for the latest version that is compatible with Cloud:

1
2
AddonQuery query = AddonQuery.builder().
    hosting(Option.some(HostingType.CLOUD)).
    withVersion(true).
    build();
Option<Addon> result = client.addons().getByKey("my.excellent.app", query);
for (Addon a: result) {
    System.out.println("I found the app; its name is " + a.getName());
    for (AddonVersion v: a.getVersion()) {
        System.out.println("And the latest Cloud version is " + v.getName());
    }
}

Rate this page: