Hi, how can I get a list of all user ids in one sh...
# support-questions
a
Hi, how can I get a list of all user ids in one shot ?
r
Hey @Alen there is no other way other than using the pagination api.
That being said, you can set a higher limit on the number of users returned per page.
a
Got it, I think earlier you had some feature right to export all ids to excel sheet.
r
Ah right. That’s not there anymore cause we have the management dashboard. The export to csv doesn’t work well with larger number of users.
a
Ok thanks, I will take a look at pagination API then.
I tried the pagination API, so in dashboard I see we have 998 users, but using API I'm getting only ids for 898 users.
which is correct ?
API one can't be correct because in our backend we have almost 975 users.
r
Hmmm. Can you set the limit to 800 and see if you get back 800?
Did you delete any users in supertokens?
a
No
800 it throws error , saying max its 600 something
r
Oh right yea.
Let me check
a
Ok
r
hey @Alen we tried calling the pagination API as well. And we got back all users.
Can you show me how you are doing pagination?
a
Copy code
async function getAllAuthorDetails(re, res) {
    // Business logic
    try {

        let nextPaginationToken = 'NTgyNDc4MmQtYWQ1MS00MGYwLWEwZGQtYTI1NGE2ZjQ2ZGE5OzE2NjcxNjg5NDgxODg='

        // get the next 500 users
        let usersResponse = await getUsersNewestFirst({
            limit: 500,
            paginationToken: nextPaginationToken,
        })

        let users = usersResponse.users;
        nextPaginationToken = usersResponse.nextPaginationToken;

        let usersID = [];

        for (const key in users) {
            usersID.push(users[key].user.id);
        }

        return res.status(200).send({
            'users': usersID,
            'nextPaginationToken': nextPaginationToken
        });

    } catch (error) {
        res.status(400).send({
            'status': 'failed',
            'message': error.message
        });
    }
}
the pagination token I got after viewing first 600 users
r
@kakashi_44 can help here.
a
Ok, it will be helpful.
k
Hey @Alen , how many users are you getting back right now? Also, the max limit allowed is 500
a
First I got 500, then it return nextPaginationToken as well. Using that paginationToken I got 401 users.
total 901
but in dashboard it shows 1,001 users.
k
okay, let me check
a
sure.
r
the dashboard uses the same API as the pagination ones.
So if the dashboard is returning 1001 users, the API too returns that many
are you talking about supertokens.com dashboard or the user management dashboard?
which is served on the API domain
a
Im talking about supertokens dashboard
r
right. Ok. @kakashi_44 please check
a
When I'm fetching using next pagination token then it returns 401 only, and it doesnt return next pagination token.
What I feel is middle 100 users are being skipped
k
How are you fetching your initial 500 users?
Copy code
js
let supertokens = require("supertokens-node");
let tpp = require("supertokens-node/recipe/thirdpartypasswordless");

supertokens.init({
    supertokens: {
        connectionURI: "<connectionURI>",
        apiKey: "<apiKey>"
    },
    appInfo: {
        websiteDomain: "http://localhost:8000",
        apiDomain: "http://localhost:8000",
        appName: "users"
    },
    telemetry: false,
    recipeList: [tpp.init({
        providers: [],
        contactMethod: "EMAIL_OR_PHONE",
        flowType: "USER_INPUT_CODE_AND_MAGIC_LINK"
    })]
});

async function users() {
    let paginationToken = undefined;
    let users = [];
    let paginatedUsers = {
        users: [],
        nextPaginationToken: undefined
    };
    let limit = 500;
    do {
        paginatedUsers = await supertokens.getUsersNewestFirst({
            limit,
            paginationToken
        });
        users.push(...paginatedUsers.users);
        paginationToken = paginatedUsers.nextPaginationToken;
    } while (paginatedUsers.users.length === limit)
    console.log(users.length);
}

users();
please replace the connectionUri and apiKey in the above code snippet and let me know what result you get
a
Sure
Im getting 1001
k
> How are you fetching your initial 500 users? ?
a
Thanks, @kakashi_44 . Using the above code only I got all the user ids list.
2 Views