Fetching Products
#
Fetching Products from AppmateThis 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.
#
1. Fetching all products:#
RequestParameter Name | Type |
---|
#
ResponseParameter Name | Type |
---|---|
products | Product[]? |
error | GenericError? |
- React Native
PurchaseClient.getProducts() .then((products) => { const productList = products; }) .catch((error) => { console.log(error.message); };
#
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.
#
RequestParameter Name | Type |
---|---|
productIdList | String[] |
#
ResponseParameter Name | Type |
---|---|
products | Product[]? |
error | GenericError? |
- React Native
const productIds = ['product_id_1', 'product_id_2'];PurchaseClient.getProductsWithIdList(productIds) .then((products) => { const productList = products; }) .catch((error) => { console.log(error.message); });
#
3. Fetching products filtered by product types:#
RequestParameter Name | Type |
---|---|
productType | String |
#
ResponseParameter Name | Type |
---|---|
products | Product[]? |
error | GenericError? |
- React Native
//Consumable => "0"//NonConsumable => "1"//Subscription => "2"
const productType = '0';PurchaseClient.getProductsWithType(productType) .then((products) => { const productList = products; }) .catch((error) => { console.log(error.message); });