Skip to main content
Solved

NodeJs REST API for grant a promotional entitlement seems not work


Forum|alt.badge.img+1

Hi: 

I’m trying to use the example exposed on the documentation:

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


sdk.auth('Bearer REVENUECAT_API_KEY');
sdk.grantAPromotionalEntitlement({duration: 'weekly'}, {
   app_user_id: 'app_user_id',
   entitlement_identifier: 'entitlement_identifier'
}).then(res => console.log(res))
  .catch(err => console.error(err));

UnhandledPromiseRejectionWarning: Error: Sorry, `grantAPromotionalEntitlement` does not appear to be a valid operation on this API.

at Proxy.<anonymous> (/path/to/index.js)

at processTicksAndRejections (internal/process/task_queues.js:95:5)

 

But I can’t do it. 

Please, someone that could give me a way to keep going.

Best answer by Jens

Hi @Jesus, for some reason, something broke about the generation of the NodeJS wrapper using the `api` library, and we haven’t been able to fix it. 

As an alternative, you can use the OpenAPI spec directly with the `api` library like this:

// Instead of this

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

// do this

const sdk = require('api')('https://docs-origin.revenuecat.com/openapi/61e6d1c8dc645600539687c6');

Let me know if this works!

View original
Did this post help you find an answer to your question?

16 replies

Jens
RevenueCat Staff
Forum|alt.badge.img+7
  • RevenueCat Staff
  • 180 replies
  • Answer
  • September 22, 2022

Hi @Jesus, for some reason, something broke about the generation of the NodeJS wrapper using the `api` library, and we haven’t been able to fix it. 

As an alternative, you can use the OpenAPI spec directly with the `api` library like this:

// Instead of this

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

// do this

const sdk = require('api')('https://docs-origin.revenuecat.com/openapi/61e6d1c8dc645600539687c6');

Let me know if this works!


Forum|alt.badge.img+2
  • Member
  • 6 replies
  • January 1, 2023

I believe this is still broken 3+ months later? Can we rely on this API or should we try to use something else instead? The fix did work so thank you! 


Forum|alt.badge.img+2

@Jens Hi! Please, link this post in the REST API doc, think it could really help! 

Thanks! :)


Forum|alt.badge.img
  • New Member
  • 2 replies
  • February 10, 2023

We tried using this: 

const sdk = require('api')('https://docs-origin.revenuecat.com/openapi/61e6d1c8dc645600539687c6');

 

try {

      sdk.auth('Bearer REVENUECAT_STRIPE_API_KEY);

      console.log('Sending purchase data to RevenueCat...')

      sdk.receipts({

        app_user_id: userId,

        fetch_token: subscriptionId,

        is_restore: 'false',

      }, {'x-platform': 'stripe', 'Content-Type': 'application/json',

      'Accept': 'application/json',}, )

      .then(({ data }) => console.log(data))

      .catch(err => console.error(err));

  } catch (error) {

    console.log('There was an error when sending purchase data to ReveneuCat: ', error);

 

The functions executes on server side, but no purchases are added to RevenueCat.

 

@Jens Do you see any mistake in the code?


Forum|alt.badge.img
  • New Member
  • 2 replies
  • February 10, 2023

@Jens 

We do get an error object back (but not always): 

FetchError: Bad Request at new FetchError (/workspace/node_modules/api/dist/core/errors/fetchError.js) at APICore.<anonymous> (/workspace/node_modules/api/dist/core/index.js:) at step (/workspace/node_modules/api/dist/core/index.js:) at Object.next (/workspace/node_modules/api/dist/core/index.js) at fulfilled (/workspace/node_modules/api/dist/core/index.js:) at processTicksAndRejections (node:internal/process/task_queues:96:5) {

status: 400,

data: { code: 7227, message: 'Content-Type not application/json' },

headers: Headers {

[Symbol(map)]: [Object: null prototype] {

date: [Array],

'content-type': [Array],

'content-length': [Array],

connection: [Array],

server: [Array],

'access-control-allow-origin': [Array],

'x-envoy-upstream-service-time': [Array]

}

},

res: Response {

size: 0,

timeout: 0,

[Symbol(Body internals)]: { body: [PassThrough], disturbed: true, error: null },

 [Symbol(Response internals)]: {

url: 'https://api.revenuecat.com/v1/receipts',

status: 400,

statusText: 'Bad Request',

headers: [Headers],

counter: 0

}

}

}


Forum|alt.badge.img+2
  • New Member
  • 2 replies
  • March 31, 2023

This workaround has stopped working altogether for me in the last 24 hours. Can anyone else confirm?

EDIT: Updating spec to latest version fixed it: https://docs-origin.revenuecat.com/openapi/6421b235414b45007a0bd1a2

 


Forum|alt.badge.img+2

I am getting the error:

Unhandled error Error: Cannot find module 'api'
Require stack: - /workspace/index.js - /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/loader.js - /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/main.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1021:15) at Function.Module._load (node:internal/modules/cjs/loader:866:27) at Module.require (node:internal/modules/cjs/loader:1093:19) at require (node:internal/modules/cjs/helpers:108:18) at /workspace/index.js:10:13 at fixedLen (/workspace/node_modules/firebase-functions/lib/providers/https.js:66:41) at /workspace/node_modules/firebase-functions/lib/common/providers/https.js:385:32 at processTicksAndRejections (node:internal/process/task_queues:96:5) { code: 'MODULE_NOT_FOUND', requireStack: [ '/workspace/index.js', '/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/loader.js', '/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/main.js' ] }

Can someone help me?


Forum|alt.badge.img+2

Nevermind.. i was in the wrong directory when typing npm install >_>


Getting the “error: Sorry, `grant Promotional Entitlement` does not appear to be a valid operation on this API.” message though.
So its not working, even with the latest version


Forum|alt.badge.img+2
  • Member
  • 6 replies
  • April 16, 2023

@Jens

 

Fix stopped working for me; am investigating:

 

```

Unhandled error Error: Unable to retrieve URL (https://docs-origin.revenuecat.com/openapi/61e6d1c8dc645600539687c6). Reason: Not Found

```

 

Edit: maybe it works? My users were getting errors, but when I do quick scripts it seems to work? However, visiting the URL does not work (https://docs-origin.revenuecat.com/openapi/61e6d1c8dc645600539687c6), while visiting other similar URL’s does work (https://docs-origin.revenuecat.com/openapi/643609ec71d2cb04b3850751).

 

Edit 2: it does not work. My local computer had it cached. Changing URL to `https://docs-origin.revenuecat.com/openapi/643609ec71d2cb04b3850751` seems to fix it?


Jens
RevenueCat Staff
Forum|alt.badge.img+7
  • RevenueCat Staff
  • 180 replies
  • April 17, 2023

@kgaidis yeah I guess the URL must have changed for some reason… Honestly I don’t know why.


Forum|alt.badge.img+6

Any update? i am getting same error.


Forum|alt.badge.img+2
  • Member
  • 6 replies
  • August 6, 2023

I was able to fix by now switching to the official(?) API:

 

```

const revenueCat = require("api")("@revenuecat/v5.1#rx9voxflgd0mr0q");

```

 

Otherwise, this temporary method originally mentioned kept breaking. It broke. I updated. It broke. etc.


Forum|alt.badge.img+6
I am using thisconst sdk = require('api')('@revenuecat/v5.1#rx9voxflgd0mr0q');

 

and getting the error.

 

You use another one? @kgaidis 


Forum|alt.badge.img+2
  • Member
  • 6 replies
  • August 6, 2023

I am currently using the one I posted just now. It worked fine for me, but maybe something is broken again.


Forum|alt.badge.img+6

Thx for your reply. It seems broken.


Jens
RevenueCat Staff
Forum|alt.badge.img+7
  • RevenueCat Staff
  • 180 replies
  • August 7, 2023

@asakirullah have you checked that you have the most recent version of the `api` package installed? I just tried it from scratch with a fresh install and the initialization above (const sdk = require('api')('@revenuecat/v5.1#rx9voxflgd0mr0q');) and it works.


Reply


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