SDK and API should have direct analogs?

  • 19 June 2023
  • 5 replies
  • 39 views

Badge +4

I’m somewhat new to this and not a seasoned developer. My app has iOS/Android versions and now a web version. For the web version I’m using the RevenueCat REST API and trying to implement the same functionality as in the mobile versions via the SDK.

 

It seems that while there are similar functionalities between them, but the contents, format, and structure of the response is different. Specifically, I am looking at the following:
SDK: Purchases.shared.getCustomerInfo

API: Get or Create Subscriber (GET v1/subscribers/{app_user_id})

 

These two items appear to be analogs to get a customer/subscriber. However there is substantially improved information available in the SDK version. For example, the SDK indicates which subscriptions/entitlements are active, whereas in the API I need to manually determine this based on the full list of subscriptions (subscriber.subscriptions.{product_id}.{expires_date}. 

 

Has anyone else had the same issue, or am I approaching things incorrectly. 


5 replies

Userlevel 5
Badge +7

Hi @op-gg-makingcoolapps . The SDKs use exactly this REST API endpoint under the hood, so you will be able to derive all of the information from that response. (For example, to derive active entitlements / subscriptions, they do the exact filtering you described)

We are working on improved REST APIs that will make consuming that information easier, but it’ll take some time for these new REST APIs to be available.

Badge +4

Gotcha, thanks Jens. As a bridging step, it might be helpful to make any functions available publicly (maybe they are) that converts the format of the API to that of the SDK, especially if it’s a single REST API call that makes up the SDK data. For example, I call the REST API from my server. I could then apply the function to convert it to the format of the SDK on the server and pass / consume on the webapp side just as I would on the mobile side. Thanks for the help/info!

Badge +4

A couple other thoughts/questions on the topic:

  1. Is there a feedback portal somewhere to provide thoughts on features/improvements to RC? I use the voting on pages in the docs, but you can only do that once per page. 
  2. Is it possible for RC to capture the Stripe customer ID and provide it via the API / SDK? I am trying to create a Stripe Customer Portal session to manage their subscription. I don’t see the Stripe customer ID captured in RC, nor can custom ID’s be set in stripe to match those in my backend / RC. This means I have to take one of a few paths 1) Capture ID in my backend 2) Pass my normal user identifier to stripe in Metadata section and then use stripe customers/search endpoint to search based on my custom ID, then fetch stripe customer ID. 

Let me know for the second item if there’s a better solution for this.

Thanks!

Badge +4

Update: I think I’ve come up with a solution. After a successful signup via stripe, I am adding a step in the stripe checkout.session.completed webhook to push the stripe customer ID to RC. Then I can call it in the subscriber API endpoint to make the portal session.

Userlevel 5
Badge +7

Let me respond to your questions in turn:

  • On the question of SDK vs API data format: as mentioned, we are working on a new version of the REST API that will make this easier; that said, our SDKs are all open source so I guess you could probably extract the transformations from there (although it is probably not very straightforward).
  • Providing thoughts on features / improvements: generally, the community is a pretty good way; or if it’s about the SDKs, you can also use GitHub issues.
  • On the Stripe customer ID question: You could use Subscriber Attributes in RevenueCat to store the Stripe customer ID.

Reply