CA
Crawlee & Apify15mo ago
afraid-scarlet

Get user payment status from actor

Hi, I have a PPR actor and want to access the user's payment status so I can prioritize their queries and set some limitations for non-paying users as well. My current actor implementation is in Node js. I understand that there is an endpoint /users/me but how do I get this info via my actor. Below is a skeletal implemention of the actor:
import { Actor } from 'apify';
import { PuppeteerCrawler } from 'crawlee';
import { router } from './routes.js';

await Actor.init();

const input = await Actor.getInput();
const startUrls = input?.startUrls || [{ url: 'https://apify.com' }];

const proxyConfiguration = await Actor.createProxyConfiguration();

const crawler = new PuppeteerCrawler({
proxyConfiguration,
requestHandler: router,
});

await crawler.run(startUrls);

await Actor.exit();
import { Actor } from 'apify';
import { PuppeteerCrawler } from 'crawlee';
import { router } from './routes.js';

await Actor.init();

const input = await Actor.getInput();
const startUrls = input?.startUrls || [{ url: 'https://apify.com' }];

const proxyConfiguration = await Actor.createProxyConfiguration();

const crawler = new PuppeteerCrawler({
proxyConfiguration,
requestHandler: router,
});

await crawler.run(startUrls);

await Actor.exit();
Thanks! 🙏
9 Replies
Saurav Jain
Saurav Jain15mo ago
@Jan Novotny will reply you soon 🙂
genetic-orange
genetic-orange15mo ago
Hi, you can get user info like this:
const user = await Actor.apifyClient.user().get();
const user = await Actor.apifyClient.user().get();
See: https://docs.apify.com/api/client/js/reference/class/UserClient#get There is isPaying flag to check if user is paying or not. So you can have:
const user = await Actor.apifyClient.user().get();
if (user.isPaying) { console.log('This user is paying') }
const user = await Actor.apifyClient.user().get();
if (user.isPaying) { console.log('This user is paying') }
afraid-scarlet
afraid-scarletOP15mo ago
Thanks! Will test it out 👍 @Jan Novotny Smooth! That works, thanks. 🚀 One last question: if a user is subscribed to the creator plan (https://apify.com/pricing), will that also show as true OR they cannot even use the actor, to begin with?
genetic-orange
genetic-orange15mo ago
The user subscribed to the creator plan will have the flag set to true. But they shouldn't be able to use the actor from the store as they have limited access to public actors.
No description
afraid-scarlet
afraid-scarletOP15mo ago
Thank you, that helps!
HonzaS
HonzaS10mo ago
@Jan Novotny can you point me where in the docs I can find the isPaying flag? I do not see it on the link you have posted.
like-gold
like-gold9mo ago
Actor.apifyClient.user().get()?.isPaying
HonzaS
HonzaS9mo ago
Thanks, but I meant some link to the docs where is this property listed with description what it means. But I guess there is not any.
protestant-coral
protestant-coral9mo ago
there are not

Did you find this page helpful?