API to get private messages

Hello Team,

I am working on android native application and using matter most v1 APIs.
I am looking for API to get list of private messages of logged user.

I can get all the posts available on public channel. I am also able to send private message using incoming webhook. But i can’t find any way to get list of private messages.

Please help.

Thanks,

Hi Jayshree,

You’re able to use the following APIs to get posts from any channel (public, private, or direct) using it’s channel ID:

  • /api/v1/channels/CHANNEL_ID/posts/OFFSET/LIMIT gets the last LIMIT posts in a channel starting OFFSET posts back from the most recent one. So an offset of 50 and a limit of 100 would get you the 50th to 150th most recent posts
  • /api/v1/channels/CHANNEL_ID/posts/TIME gets all posts made in that channel since the given Unix timestamp

Also, so you have some advanced warning, our upcoming release will be replacing the v1 APIs due to some substantial internal changes to our code. You can read more about it here. At this time, the above APIs will be moved to

  • /api/v3/channels/CHANNEL_ID/posts/page/OFFSET/LIMIT
  • /api/v3/channels/CHANNEL_ID/posts/since/TIME

Thank you very much.

Yes, now i can read all the posts from direct channel too. Thanks to you.
Well, is there any mechanism to get notify the client, whenever any new message is posted to public or private channel.

Will push notification work at this time ?
I want to get any kind of notification from matter most server, so i can show a notification to user that new message is arrived.

Awaiting for your reply.
Thanks.

Using a websocket is probably your best bet. They transmit a lot more events than push notifications do, and they’re what the web client currently uses.

Unfortunately, like the REST api, it doesn’t have any documentation yet. If you’re comfortable reading Javascript, a list of all the socket event names are here and the code that handles them on the web client is here

Hi, Can you please tell me what wss URL i should use here. I am not able to make the connection with mattermost either using ws or wss.

Thanks,
Jayshree

The URL is wss://SERVER/api/v1/websocket, but will soon be wss://SERVER/api/v3/websocket. wss is preferred.

Hi,

Thanks. It’s working awesome.

Thanks,
Jayshree.