Server connection error

Hi, I have facing a sendbird server connection error. And the code I wrote is below.

<script>
// sendbird settings
sb = new SendBird({
    appId: "app_id_test"
});
sb.connect("ahn_test", "session_token_test", function(user, error) {
    console.log(user);
    console.log(error);
});

// group channel 

sb.GroupChannel.getChannel("xyz_url", function(groupChannel, error) {
    if (error) {
        return;
    }

    console.log(groupChannel);

    groupChannel.enter(function(response, error) {
        if (error) {
            return;
        }
    })
 });

And the chrome developer console print this error like below.

And also the error statement on the api url is like below.

{“message”:“Invalid value: “Api-Token. Api-Token is missing.”.”,“code”:400401,“error”:true}

I thought sendbird js connection with “user_id” and “session_token” is the only thing that requires for connection not “api_token”. How can I fix this problem?

Thanks in advance :slight_smile:

Hi, Moomoo

Please replace

With your actual APP_ID you get from dashboard.sendbird.com

You can follow the instructions here:

You will have to change “session_token_tst” for your actual token (you obtain a token from your Dashboard as well)

More details here: Authentication | Chat JavaScript SDK | Sendbird Docs

Accessing Channels

This may cause an error as well. Please refer to this for creating channels:

Hi Walter, thanks for the reply.

Actually the value above are just an examples and I wrote the real values. And cannot expose it so i just replace to some random strings for security issue.

Is there any other reason that can yield this problem?

Nice catch!

What I see is that you need to be connected before accessing your channels. Please try this:

sb.connect("ahn_test", "session_token_test", function (user, error) {
    console.log(user);
    console.log(error);
    
    if (!error) {

        // Once we are connected and no error is present...

        sb.GroupChannel.getChannel("make-sure-this-channel-exists-just-in-case", function (groupChannel, error) {
            if (error) {
                return;
            }
            console.log(groupChannel);
            groupChannel.enter(function (response, error) {
                if (error) {
                    return;
                }
            })
        });
    }

});
1 Like

Walter, Finally realize why this happened!

I allowed the localhost domain and connection works!

Thanks for the kind helps again walter! :slight_smile: