The Marketplace V2 REST APIs are deprecated.
The Marketplace V2 REST APIs (the /rest/2 endpoints, including the marketplace-client-java library and the tutorials in this section) have been deprecated and are being disabled. Requests to these endpoints will fail with an HTTP 410 Gone response and an API_DEPRECATED error. Please migrate to the V3 Marketplace REST APIs. For more details and migration guide, see the changelog (CHANGE-3257).
Example error response:
1 2 3 4 5 6{ "message": "This V2 API has been deprecated and disabled for your account. Please migrate to V3 Marketplace APIs.", "error": "API_DEPRECATED", "statusCode": 410, "migrationGuide": "https://developer.atlassian.com/platform/marketplace/changelog/#CHANGE-3257" }
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.
You will need:
marketplace-client-java libraryMarketplaceClient objectThe 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 3 4 5 6 7 8 9Option<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"); }
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 3 4 5 6 7 8 9 10 11AddonQuery 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 3 4 5 6 7 8 9 10 11 12AddonQuery 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: