Skip to main content
Question

Best option for getting user entitlements on web


Forum|alt.badge.img+1

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

cody
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • 492 replies
  • May 4, 2023

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


Forum|alt.badge.img+1
  • Author
  • New Member
  • 1 reply
  • May 5, 2023

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

 

Thanks


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings