Skip to main content

I have a React Native application using RevenueCat, so there are two apps - 1 for Android and 1 for iOS, and therefore two public API keys. I’m wanting to use the endpoint for creating a new subscriber/customer on my backend server (https://api.revenuecat.com/v1/subscribers/{app_user_id}) rather than doing it on the front end, but the issue I’m having is I don’t know which platform the user is/will be using and so not sure which API key to use with the endpoint. Does this matter or am I able to use whichever endpoint and the subscription be acceptable on either platform?

 

(I’m specifically granting the customer an entitlement after creating them, if that makes any difference.)

 

Thanks so much in advance!

Hey @jagmcn1209 ! 

 

Authentication for the RevenueCat REST API is achieved by setting the Authorization header with a valid API key based on the platform that the call is being made on. See our Authentication guide for more information.

 

I would recommend using the SDK to check the platform first before you make the call so you can successfully pass in the correct API key. If you are using react-native, this could be done by importing Platform from react-native and then using that value to determine the current platform of the user. Similar to the code snippet found below: 

import { Platform } from 'react-native';

//...

export default class App extends React.Component {

componentDidMount() {
Purchases.setLogLevel(Purchases.LOG_LEVEL.DEBUG);

if (Platform.OS === 'ios') {
await Purchases.configure({ apiKey: <public_apple_api_key> });
} else if (Platform.OS === 'android') {
await Purchases.configure({ apiKey: <public_google_api_key> });

// OR: if building for Amazon, be sure to follow the installation instructions then:
await Purchases.configure({ apiKey: <public_amazon_api_key>, useAmazon: true });
}

}
}

 

Let me know if that helps!