Skip to main content

When I test the /subscribers/{app_user_id} endpoint on the API reference page using my public key, I get a 200 response.

However, when I run the same code from my Node cloud function, I consistently get back a 401.

Any ideas as to why this is? 

Can you share the error message you’re getting along with the 401? Are you authenticating correctly with the authorization header and `Bearer <YOUR_API_KEY>`


Yes, certainly.

I am setting the Authorization header with my api key using the “Bearer <API_KEY>” format.

Also, I checked the url, and it’s good.

When I print the error object, I get a status of “401” and a statusText of “Unauthorized”.

What is returned is the following object:

{ timeout: 0, size: 0 }

 


I discovered a workaround.

 

This code gives me the 401

const sdk = require('api')('@revenuecat/v4.0#fawmbsl21aqc0w');

sdk.subscribers({
app_user_id: 'app_user_id',
Authorization: 'Bearer <API_KEY>'
})
.then(res => console.log(res))
.catch(err => console.error(err));

 

If I instead use axios, I get the happy response

const axe = axios.create({
baseURL: 'https://api.revenuecat.com/v1/subscribers',
headers: {
'Authorization': 'Bearer <API_KEY>'
}
});

axe.get('/app_user_id')
.then((response) => console.log(response.data))
.catch(() => console.log(e));

 


The Node snippet in the documentation didn’t work for me either, but I was able to get it to work by letting the api package handle the authorization header:

 

const sdk = require('api')('@revenuecat/v4.0#fawmbsl21aqc0w');    

sdk.auth('<API_KEY>')
sdk.subscribers({app_user_id: `app_user_id`})
.then(res => console.log(res))
.catch(err => console.error(err))

 


Reply