Question

Best option for getting user entitlements on web

  • 2 May 2023
  • 2 replies
  • 64 views

Badge

I have a mobile app ready to go using RevenueCat, I want to hook up a web equivalent of checkout.

 

I can see a guide on how to connect stripe, but purchasing isn’t the only thing RevenueCat is concerned with, what about getting user entitlements?

 

I can do something like:

 

const res = await fetch(
`https://api.revenuecat.com/v1/subscribers/${user.id}`,
{
headers: {
'Authorization': `Bearer ${'appl_x'}`,
'Content-Type': `application/json`,
'X-Platform': 'ios',
'accept': 'application/json',
},
},
)
.then((res) => res.json())
.then((res) => {
const entitlements: Record<string, PurchasesEntitlementInfo> =
{}
if (res?.subscriber?.entitlements) {
Object.keys(res.subscriber.entitlements).map((v: string) => {
const value = res.subscriber.entitlements[v]
const activeSubscription =
res.subscriber.subscriptions?.[value.product_identifier]
entitlements[v] = {
expirationDate: value.expires_date,
isActive: new Date(value.expires_date) >= new Date(),
latestPurchaseDate: value.purchase_date,
willRenew: !activeSubscription?.unsubscribe_detected_at,
productIdentifier: value.product_identifier,
} as any
})
}
return { data: { all: entitlements } }
})

 

but this seems kind of crazy, is there some form of web SDK I’m missing?


2 replies

Userlevel 6
Badge +8

Hey @kyle-ssg! 👋

We don’t currently provide a web SDK, so using the REST API directly would be the best way to get entitlements from the web right now. You can read more about the GET /subscriber endpoint here: https://www.revenuecat.com/reference/subscribers

Badge

Thanks for the reply. Ok yeah so the endpoint mentioned in my question.

 

Thanks

Reply