0

I'm creating a chat app with react-chat-engine but I don't know how to make a post request to add users in chat room in react-chat-engine. I have referred this link- how to make a post request to create new users in react-chat-engine and now I want create new chat room in which I want to add members through post request.

I tried using POSTMAN but I cannot find a correct combination of the url the post request has to be sent to, headers and body. Some of the combinations I tried and the resulting errors are following:-

Method 1 Body

Method 1 Header

Method 2 Body

Method 2 Header

(I have removed the private key in screen shot)

Please help me out.

  • Tips: Use the snippete tool and post your attempt at solving the issue. Next also add any errors you're getting with your current code. Avoid using links and images to showcase your problems as they can break and not be useful for future users. – Sebastian Gbudje Jan 16 '22 at 17:38
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jan 25 '22 at 15:53

1 Answers1

0

How to create a new chat:

import axios from 'axios';

export const newChat = (title, projectId, username, secret, callback) => {
  axios
    .post(
        `https://api.chatengine.io/chats/`, 
        { title: title }, 
        { headers: { 
            "Public-Key": projectId, 
            "User-Name": username, 
            "User-Secret": secret 
        } }
    )

    .then((response) => {
      callback && callback(response.data);
    })

    .catch((e) => console.log('New Chat Error', e));
};

How to add a User to a chat:

import axios from 'axios';

export const invite: Invite = (chatId, inviteUsername, projectId, username, secret, callback) => {
  axios
    .post(
        `https://api.chatengine.io/chats/${chatId}/people/`, 
        { username: inviteUsername }, 
        { headers: { 
            "Public-Key": projectId, 
            "User-Name": username, 
            "User-Secret": secret 
        } }
    )

    .then((response) => {
      callback && callback(response.data);
    })

    .catch((e) => console.log('Invite Error', e));
};
Adam LaMorre
  • 655
  • 7
  • 21
  • Thanks for a quick response. I tried but it is not working. It is not giving any error but it is also not adding the user in the chat room. body: `{ "username":"arzoo" } ` headers:`{"Public-Key": "c75f6ddd-fdca-4953-94b0-ede7c092ff2a", "User-Name": Admin, "User-Secret": 123 }` And the result is : [ { "person": { "username": "Admin", "is_online": true }, "chat_updated": "2022-01-16T16:57:37.881813Z", "last_read": null } ] – Arzoo Goyal Jan 16 '22 at 18:11