Ankur Sharma
Ankur Sharma

Reputation: 425

sendbird error 400 bad request /user not found

I am trying to play with sendbird. I am getting this error . I am trying to make sendbird api work in react.js app. I have read the documentation and it wasnt clear to me. I have looked at stackoverflow earlier replies and Thats why , i tried to create channel after i get connected to sendbird.

   VM2257:1 POST https://api.sendbird.com/v3/group_channels 400 (BAD 
   REQUEST)

error is here p {name: "SendBirdException", code: 400201, message: "User not found."}

I am trying to implement it in react.js . Here's my code. Can someone help me out with how to rectify this error.

    import React, { Component } from 'react';
import * as SendBird from 'sendbird';
import './App.css';
var sb = new SendBird({'appId': '59BEEA34-BDC7-461B-B10B-63705C8B57C2'});


class App extends Component {


  componentWillMount(){

    sb.connect("ankur1", function(user, error) {
     if(user){
       console.log("looks like connected",user)
       var userIds = ['unique_user_id1', 'unique_user_id2','ankur1'];
       var name = "amazing1";
       sb.GroupChannel.createChannelWithUserIds(userIds, false, name,  function(createdChannel, error) {
         if (error) {
             console.error("error is here",error);
             return;
         }

         console.log("success",createdChannel);
       });
     }
     else{
       console.log("looks like error")
     }

    })
  }


  sm(){
    console.log("button clicked",sb)
    var channel = "amazing"
    /*
    sb.channel.sendUserMessage("that is cool", '', function(message, error){
    if (error) {
        console.error(error);
        return;
    }

    console.log(message);
});
*/



  }

  componentDidMount(){


  }
  render() {
    var sm = this.sm.bind(this)
    return (
      <div>

      <h1>ankur is here </h1>
      <button onClick={sm}>click here</button>

      </div>
    );
  }
}

export default App;

Upvotes: 0

Views: 1550

Answers (1)

eoamusan
eoamusan

Reputation: 11

I actually had a similar problem yesterday. Googling around it actually led me here. Eventually, I found a way around it.

So, the first thing I do after creating the connection to SendBird is to create a connection for that user I wish to connect to.

var sb = new SendBird({
    appId: 'YOUR SENDBIRD APP ID HERE'
});

sb.connect(UNIQUE_USER_ID, function(user, error) {
              connectToUser();
          });

function connectToUser(){
    sb.connect(YOUR_OWN_USERID, function(user, error) {

        sb.GroupChannel.createChannelWithUserIds([UNIQUE_USER_ID], true, UNIQUE_USER_ID+YOUR_OWN_USERID, '', '', '', function(createdChannel, error){

            $scope.chatChannel = createdChannel;

            if (error) {
                console.log(error);
                return;
            }
        });         
    });
}

Then, you can proceed to send your messages using the createdChannel

$scope.chatChannel.sendUserMessage(YOUR_MESSAGE_HERE, '', '', function(message, error){
        if (error) {
            console.error(error);
            return;
        }

        console.log(message);

    });

Let me know if that works.

Upvotes: 1

Related Questions