Reputation: 1
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 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:-
(I have removed the private key in screen shot)
Please help me out.
Upvotes: 0
Views: 620
Reputation: 695
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));
};
Upvotes: 0