CommunityRepository.getCommunities returns an empty array

I have 2 public communities in the console panel. Using same user that created the communities and the following code:

CommunityRepository.getCommunities(
    {},
    ({ data: communities, loading, error }) => {
      if (error) {
        console.log(error)
      }
      if (loading) {
        console.log("Loading...")
      }
      if (communities) {
        console.log(communities)
      }
    },
  );

I see an empty communities array logged in the console.

Hello @dmitryvm, could you please confirm which TS SDK version you are using at the moment?

Hello, the version is : "dependencies": { "@amityco/ts-sdk": "^6.33.1",

Hello @dmitryvm ,
Our team recommends trying the following approach:

const unsubscribe = CommunityRepository.getCommunities(
  { membership: 'member', limit: 10 },
  (data) => {
    console.log('data: ', data);
  }
);

Please give this a try and let us know if you need any further assistance.

The code above also logged an empty array and I need a list of all public communities , so the user can pick which one to join.

console.log(await CommunityRepository.getCommunityByIds(["67938f282c21966a7babefb4"]))

Throws an exception ```
Uncaught (in promise) ASCApiError: Amity SDK (400400): Some community not found
at new ASCApiError (index.esm.js:638:9)
at unwrapPayload (index.esm.js:1576:15)
at createHttpTransport.use (index.esm.js:1745:13)
at async Axios.request (Axios.js:40:14)
at async Object.getCommunities$1 [as getCommunityByIds] (index.esm.js:35021:31)
at async loadCommunities (page.tsx:18:15)

![communitydetails|690x400](upload://h8CM4OncGtKzIyMLjNhqxhZVIRh.png)

I am sorry. It looks like my issue is solved. I had 3 apps in the console and was creating communities in the wrong one.

1 Like