Question

[EXPO] How to fetch products from RevenueCat? Why does Purchase.getProducts(['productId']) return empty array?

  • 18 July 2022
  • 5 replies
  • 137 views

Badge

I have created a product in google play console, and I also created a revenuecat product with the same id, but the the following line of code returns an empty array.


// Fetching all products by passing an array of their product_id
const products = await Purchases.getProducts(['product_id']);

// Printing the list of products available.
console.log(products);


// Example response:
[]

Project info:

  • Expo SDK version: 45
  • React native: 0.68.2
  • react-native-purchases: 4.6.1
  • Device tested: android

5 replies

Userlevel 5
Badge +10

Hey @kunga_tashi 

Have you had a chance to take a look at this community post?

Oftentimes when developers are having issues fetching their products, it is due to a step missing from the community post above. 

Badge +1

I am having the same problem. The lack of insights into the problem is driving me crazy :-)

 

Can’t RC log relevent info whenever we encounter problems like this!?

 

E.g. if I pass id’s that do not exist please state so and list the available ones.

 

I guess the api’s towards App Store and Play Store has this capability!?

 

I have tried everything (I think) now but the result is always an empty list.

Badge

Hi @kunga_tashi,

I have the exact same issue on the same tech stack. Have you been able to solve this issue?

Would be great if would share some insights :)

Thank you

Roman

Badge

Hey @Roman Zinnatov ,

I found an alternative solution to this problem which I think might be helpful. 
So instead of using the Purchases.getProducts() method, try configuring offerings and packages and then use the Purchases.getOfferings() method.

If you go to the revenuecat dashboard, just above the products section, you will see an offerings section, create one offering which would act like a container for all your packages. Once you have created the offering, you will see it reflect on the right side. You can click on that and then proceed to create packages. You can consider each package as equivalent to your product, what you have to do is attach a product to a specific package.
 

This link contains how to fetch the offerings once setup - Display in app purchases 
This method worked well for me, and the offerings were getting fetched. Do let me know if its working for you or not. 

Kunga

Badge

@kunga_tashi 

Kunga,

Thank you so much for such a quick reply!

Guys from RevenueCat support pointed out to the doc of .getProducts method. It turned out that it has second input parameter, which is optional and has default value as SUBS.

I didn’t specify it, so once I passed INAPP as the second param to .getProducts, it started to return my products instead of an empty array.

Hope it would help someone.
Roman

Reply