How can you create a group?

I am unable to create a group. What am i missing? How do you use the various api keys?

1 Like

There are two options you can take to create a group.

  1. Either you can create a group using the REST API key
  2. Or login as a user(two approaches), and then a user creates a group.

CREATE A GROUP USING THE REST API

For this you need to first find your REST API KEY:

  • Once you login, create or choose an existing app
  • On the left navigation of your app, Click on API keys
  • Click on Rest API Keys tab on the main content to find them.
  • You can also add additional API keys on this page

By default only one REST API Key is created. This is the api key you will need to create a group using REST[1]. We currently don’t have sample code to create a group using REST api, but you can paste you api key, enter a group name and actually hit our API from the documentation page itself [1].

IF YOU CHOOSE TO ALLOW USERS TO CREATE GROUPS

Creating a group using the client-side SDK requires creating a user and logging in as the user before creating a group.

CREATING A USER
You can create a user either using the REST apikey or client-side SDK eg: javascript [2]
When creating a user using REST - passing the withAuthToken=true will return a token you can login with.
​You can now login as this user choosing one of two approaches.

LOGGING IN AS A USER USING AUTHTOKEN
In this approach - you do not need the API key to login, but use a string called the AuthToken (mentioned in previous step when creating a user). You can login as any user using their respective AuthToken. [3]

LOGGING IN AS A USER USING UID, APIKEY
In this approach - you call CometChat.login() with the uid and api key as parameters.[4]

Once logged in you can allow users to create groups using CometChat.CreateGroup [5].

Once again to summarize you can either create a group using REST api using [1]
OR you need to login (two approaches) and then create a group using [5].

Also note that the group guid when creating a group cannot contain spaces or punctuation apart from hyphen and underscore eg: “my-group” and “old_school” are both allowed, but “rocks!” isn’t.

Hope this helps.

[1] https://prodocs.cometchat.com/reference#createuser (please use ?withAuthToken=true)
[2] https://prodocs.cometchat.com/docs/js-users-user-management#creating-a-user
[3] https://prodocs.cometchat.com/docs/js-authentication#login-using-auth-token
[4] https://prodocs.cometchat.com/docs/js-authentication#login-using-auth-only-api-key
[5] https://prodocs.cometchat.com/docs/js-groups-create-group

1 Like