Can't create new channel
When trying to create a new channel, I get a 400 bad request error with message
{"code":4,"message":"GetOrCreateChannel failed with error: \"When using member based IDs specify at least 2 members\"","StatusCode":400,"duration":"0.00ms"}
The way I'm creating this is
val channelDetails = hashMapOf<String, Any>()
channelDetails["name"] = myChannelName
channelDetails["owner"] = "myOwnerUniqueId"
val channelType = ChannelType.DIRECT.name
val newOrExistingChannel = streamClient.channel(channelType, channelDetails, formattedChannelIds) // list of unique member ids which might have been created or not. Always 2+
What could I be doing wrong here?
That looks like a bug in the Java SDK where it's not actually sending you the members.
@tbarbugli and @adrian09h
@tschellenbach these member ids hasn't been created on Stream yet, would that be an issue?
Yes, that's also an issue. You need to create the users before creating the channel.
On Thu, Oct 17, 2019 at 2:45 PM chikrix [email protected] wrote:
@tschellenbach https://github.com/tschellenbach these member ids hasn't been created on Stream yet, would that be an issue?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GetStream/stream-chat-android/issues/184?email_source=notifications&email_token=AACAZQMIFUJ4FVXXLKQGVR3QPDFGPA5CNFSM4JB6ANV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBRO4VI#issuecomment-543354453, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACAZQONDXHNI5DMQFUXEFLQPDFGPANCNFSM4JB6ANVQ .
Ok. Thanks. I think that's my issue then. The message isn't very informative about that.
I think there is something wrong with the Java SDK, our team will look into it
On Thu, Oct 17, 2019 at 2:48 PM chikrix [email protected] wrote:
Ok. Thanks. I think that's my issue then. The message isn't very informative about that.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GetStream/stream-chat-android/issues/184?email_source=notifications&email_token=AACAZQJ6YTJBUJHPZJML5DDQPDFSNA5CNFSM4JB6ANV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBRPFHQ#issuecomment-543355550, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACAZQOZAOOVFUGTLCW7GG3QPDFSNANCNFSM4JB6ANVQ .
@Chikrix did you try using IDs of existing users?
Hi, @Chikrix. Thanks for your reporting.
Atm I have some questions for your creating channel.
What are formattedChannelIds and ChannelType.DIRECT.name?
StreamChat provides predefined types of Channel such as livestream, messaging, gaming, commerce and team
https://getstream.io/chat/docs/#channel_features
Please use messaging type.
And try below code.
val client = StreamChat.getInstance(this.application)
val extraData = HashMap<String, Any>()
extraData["name"] = "your-channelName"
val members = ArrayList<String>()
members.add("yourUserId")
members.add("member1") /*Member(s) must be registered already to SteamChat*/
members.add("member2")
// ...
extraData["members"] = members
val channelId = "your-channelId"
val channel = Channel(client, ModelType.channel_messaging, channelId, extraData)
val request = ChannelQueryRequest().withMessages(10).withWatch()
channel.query(request, object : QueryChannelCallback {
override fun onSuccess(response: ChannelState) {
}
override fun onError(errMsg: String, errCode: Int) {
}
})
One more:
About channelDetails["owner"] = "myOwnerUniqueId"
If you were going to use this to confirm channel owner, you don't need this field.
StreamChat exposes created_by field in ChannelState as a User model.
@tbarbugli the id's are not that of existing users as I haven't created them yet, so I guess that must have been the cause of my issue, I'm going to create new users and try again with their member IDs.
@adrian09h I'm using my own custom types, I'm doing that because I'm migrating my data from Layer and used those two as my conversation types there. So I'm assuming that I need to use the same types as well for the data migration. formattedIds are just memberIds (formatted because I have to change my existing name format to suit Streams, removing : ). ChannelType.DIRECT.name is one of my custom channel type ("direct"). What do you think about this? I'll modify my code based on your example. Thanks
StreamChat doesn't provide the other channel type.
Please read this again
https://getstream.io/chat/docs/#channel_features
livestream: Sensible defaults in case you want to build chat like YouTube or Twitch. messaging: Configured for apps such as Whatsapp or Messenger. gaming: Configured for in-game chat. commerce: Good defaults for building something like your own version of Intercom or Drift. team: If you want to build your own version of Slack or something similar start here.
In your case, you must set channel type by messaging
Thanks @adrian09h. According to your docs, it says we can create our own custom channel types, so shouldn't direct work? Also, I want to be able to distinguish between one on one channel types and group conversations, how do I go about that if I want to use the messaging type? Also, there's something I don't understand about the channel types which isn't very clear, how would they differ in terms of performance and behaviour, it'll be great if there's more information on this in the docs as not everyone is familiar with those apps or the specific behaviours that separate them
@Chikrix , Sorry for my wrong comment, you can create your own type of channel. However you need to add the type(s) on dashboard before creating your own type channel.
- Open your Stream dashboard
- Navigate to your app
- Menu/ Chat / Chat Overview
- Chat Types/ Add Chat Type
- Set the necessary items here.
Thanks @adrian09h
I'm facing an issue with channels created using the latest version. The code to create the channel is the same as I used earlier while I was using v2.3.0 (based on the example you provided above @adrian09h). Now when I try to create a channel and try to load channels, I get a NullPointerException with message Attempt to invoke virtual method 'java.util.Date com.getstream.sdk.chat.rest.Message.getDeletedAt(). Please, what could be the cause and how can I fix this? If I use the previous version of the library 2.3.0, this works, but with the latest version 3.0.0 it throws this exception.
@Chikrix , the issue was fixed by @elevenetc . Please try new version 3.0.1.
I'm receiving this issue with the latest client 3.3.0. If I create the channel like so (kotlin):
val channel = client.channel(ModelType.channel_messaging, hashMapOf<String, Any>(), listOf(user, userToChatWith))
it leads to this error:
GetOrCreateChannel failed with error: "When using member based IDs specify at least 2 members"
I tried with setting the channelId explicitly however that leads to an unreadable channel for the second user to join:
val channelId = listOf(user, userToChatWith).sorted().joinToString("-")
val channel = client.channel(ModelType.channel_messaging, channelId, hashMapOf<String, Any>("members" to listOf(user, userToChatWith)))
which leads to this error for the second user (works fine for the user starting the channel):
GetOrCreateChannel failed with error: "User 'chuck' with role user is not allowed to access Resource ReadChannel on channel type messaging when I try to .watch the channel.
Both users are being created as a part of a log in process via a nodejs backend:
const client = new StreamChat(apiKey, apiSecret);
const user = Object.assign({}, data, {
id: req.user.sender,
role: 'user',
image: `https://robohash.org/${req.user.sender}`,
});
const token = client.createToken(user.id);
await client.updateUsers([user]);
What am I doing wrong?
Okay, on further investigation I think I may have found a bug in the library. If I initialize the channel with a
channel.watch(ChannelWatchRequest(), object : QueryWatchCallback {
it seems to fail to pass the member information in the body of the request, causing the above error. Changing this to:
channel.query(ChannelQueryRequest().withMessages(25).withWatch(), object : QueryChannelCallback {
seems to work great. Is there some semantics around .watch I'm missing or is this a bug?
@elevenetc @adrian09h
@psylinse thanks for reporting the problem. I created separate issue for your problem: https://github.com/GetStream/stream-chat-android/issues/422
This is absolutely not fixed @elevenetc . And still hitting this issue on python client. And the docs do not even match up... this code is a disaster...
https://getstream.io/chat/docs/python/creating_channels/?language=python
channel = Channel("messaging", None, custom_data=dict(members=["thierry"]))
# Note: query method creates a channel
channel.query()
this doesn't work. the signature isn't even consistent with what the python SDK expects...
channel = Channel("messaging", "general")
channel.create("<user-id>")
this is also inconsistent with what library expects. I'm calling this from my backend python server and i'm getting 👍
stream_chat.base.exceptions.StreamAPIException: StreamChat error code 4: GetOrCreateChannel failed with error: "When using member based IDs specify at least 2 members""
what is going on here? almost nothing i've tried in docs is working. is this project still being maintained at all?
Many years later this is still very much an issue.
Facing this issue with the JS SDK. @nh2d Did you perhaps figure out what was wrong?


