Skip to main content

Fetching Products

Fetching Products from Appmate#

This page describes how to fetch the products. With the getProducts method of PurchaseClient, you will get the active products synced with the Google Play Store, Huawei App Gallery and Apple App Store.

If you have created some products for your app for the first time, it may take time to get synced products, as Google has a time delay in activating the products.

After you called getProducts method, the products will be cached in the sdk for 10 minutes. So you will be able to get the response faster than getting directly from the network. If you add a new product and want to see it in your app for testing purposes, you can delete your app's cache. The products will be fetched from the network the next time you open your app. getProducts method returns products in the form of ProductsResponse. If you failed to fetch products, error field in the ProductsResponse will not be empty.

You can access the list of all products, list of some spesific products or the list of products filtered by product types.

To handle the result of the asynchronous operation, you must use await as shown in the following code:

1. Fetching all products:#

Request#

Parameter NameType

Response#

Parameter NameType
productsList<Product>?
errorGenericError?
ProductsResponse response = await PurchaseClient.getProducts();if (response.error != null) {  print(response.error!.message!);} else {  List<Product> products = response.products!;}

2. Fetching products by specifying a list of some productIds: #

When calling getProductsByProductIdList(), pass a productIdList that specifies a list of product ID strings created in the Creating Products page of our web console.

Request#

Parameter NameType
productIdListList<String>

Response#

Parameter NameType
productsList<Product>?
errorGenericError?
List<String> productIdList = ["product_id_1", "product_id_2"];ProductsResponse response = await PurchaseClient.getProductsWithIdList(productIdList);if (response.error != null) {  print(response.error!.message!);} else {  List<Product> products = response.products!;}

3. Fetching products filtered by product types: #

Request#

Parameter NameType
productTypeString

Response#

Parameter NameType
productsList<Product>?
errorGenericError?
//Consumable => "0"//NonConsumable => "1"//Subscription => "2"
String productType = "0";ProductsResponse response = await PurchaseClient.getProductsWithType(productType);if (response.error != null) {  print(response.error!.message!);} else {  List<Product> products = response.products!;}