Skip to main content
Question

`500 Internal Server Error: RevenueCat Entitlement Grant after Gift Code Validation`

  • September 24, 2025
  • 1 reply
  • 42 views

Forum|alt.badge.img

We are implementing a gift code redemption feature for our app, integrating with Airtable for code validation and RevenueCat for entitlement management. The backend is built with Strapi (Node.js), and the app is Kotlin Multiplatform (Android & ios). We have two plans monthly and annual.

**The Flow:**
1. User redeems a gift code in the app
2. App calls our backend `/api/grant-entitlement` endpoint
3. Backend validates the code in Airtable
4. Backend attempts to grant an entitlement via RevenueCat API

**The Problem:**
We are consistently encountering a **500 Internal Server Error** from our backend (`dev-api.myatlas-health.com/api/grant-entitlement`) when it tries to call the RevenueCat API.

**Debugging Steps Taken:**
1. ✅ Initially attempted to use RevenueCat v2 grant endpoint with `expires_at`
2. ❌ Discovered that RevenueCat does not have a v2 grant endpoint (404 error)
3. ✅ Switched to RevenueCat v1 promotional endpoint: `/v1/subscribers/{userId}/entitlements/{entitlementId}/promotional`
4. ❌ Found that v1 promotional endpoint doesn't accept `expires_at`, requires `duration` parameter
5. ✅ Updated backend to use v1 promotional endpoint with `duration` parameter
6. ✅ Confirmed via direct `curl` to `api.revenuecat.com` that the v1 promotional endpoint with `duration` is correct (received "Invalid API Key" instead of 404/illegal parameters)
7. ✅ Identified and fixed Strapi permissions issue - enabled `grantEntitlement` permissions for 'Public' role
8. ✅ Backend has been deployed multiple times after each fix
9. Revenucat api is found in system but unable to find in swagger documentation.

**Current Status:**
Despite these changes, our `dev-api.myatlas-health.com/api/grant-entitlement` endpoint still returns a 500 Internal Server Error.

**Backend Code (Current):**
```javascript
// RevenueCat v1 promotional endpoint
const revenueCatUrl = `https://api.revenuecat.com/v1/subscribers/${userId}/entitlements/${encodedEntitlementId}/promotional`;

const response = await axios.post(revenueCatUrl,
{ duration: duration }, // "monthly" or "yearly"
{
headers: {
Authorization: `Bearer ${appConfig.revenueCatApiToken}`,
'Content-Type': 'application/json',
},
}
);
```

**What We Need Help With:**
- Why is our deployed Strapi backend still failing with a 500 error when calling RevenueCat v1 promotional API?
- Could this be related to environment variables (RevenueCat API key configuration)?
- Are there additional Strapi configuration requirements we're missing?
- Is there an unhandled exception in our backend logic that we should catch?

**Environment:**
- Strapi v4.14.4 (Node.js)
- RevenueCat API v1 promotional endpoint
- AWS-hosted backend
- Gift codes validated via Airtable integration

Any guidance on debugging this 500 error would be greatly appreciated!
```

This post has been closed for comments

1 reply

chris_perriam
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • September 26, 2025

The documentation for our Grant an Entitlement API can be found here: https://www.revenuecat.com/docs/api-v1#tag/entitlements/operation/grant-a-promotional-entitlement

In your code, I’d recommend checking the following:

  • Are ${userId} and ${encodedEntitlementId} being populated with their intended values?
  • Are your headers being set correctly? I notice that Authorization is missing quotes
  • What response is returned by RevenueCat? There may be an error before or after axios.post which is causing the 500 from your backend
  • Are you using a valid v1 API key for the project? An example is shown in my attached screenshot

It can also be helpful to manually make requests using cURL in your local environment to validate that the request URL, headers and body are all correct.

Hope this helps! Let me know if you’re still experiencing issues and we can work through them together.