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: https://docs.sendbird.com/javascript/authentication#3_connect_to_sendbird_server_with_a_user_id_and_an_access_token

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: