Apify

Apify and Crawlee Official Forum

b
F
A
J
A

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:

Plain Text
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! πŸ™
3
S
J
m
10 comments
will reply you soon πŸ™‚
Hi, you can get user info like this:
Plain Text
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:
Plain Text
const user = await Actor.apifyClient.user().get();
if (user.isPaying) { console.log('This user is paying') }
Thanks! Will test it out πŸ‘
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?
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.
Attachment
Snimek_obrazovky_2024-03-12_v_14.00.32.png
Thank you, that helps!
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.
Actor.apifyClient.user().get()?.isPaying
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.
there are not
Add a reply
Sign up and join the conversation on Discord
Join