# API to get private messages

**URL:** <https://forum.mattermost.com/t/api-to-get-private-messages/1388>\
**Category:** Troubleshooting\
**Created:** [April 27, 2016, 10:13am UTC](https://forum.mattermost.com/t/api-to-get-private-messages/1388 "2016-04-27T10:13:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayshree.rathod](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jayshree.rathod](https://forum.mattermost.com/u/jayshree.rathod)\
**Post date:** [April 27, 2016, 10:13am UTC](https://forum.mattermost.com/t/api-to-get-private-messages/1388/1 "2016-04-27T10:13:04Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![hmhealey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/hmhealey/32/1915_2.png) [@hmhealey](https://forum.mattermost.com/u/hmhealey)\
**Post date:** [April 28, 2016, 2:33pm UTC](https://forum.mattermost.com/t/api-to-get-private-messages/1388/2 "2016-04-28T14:33:26Z")

</div>

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](https://forum.mattermost.com/t/web-service-api-changing-recommend-using-drivers/1327). 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

---

<div class="post-metadata">

**Author:** ![jayshree.rathod](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jayshree.rathod](https://forum.mattermost.com/u/jayshree.rathod)\
**Post date:** [April 29, 2016, 4:48am UTC](https://forum.mattermost.com/t/api-to-get-private-messages/1388/3 "2016-04-29T04:48:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hmhealey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/hmhealey/32/1915_2.png) [@hmhealey](https://forum.mattermost.com/u/hmhealey)\
**Post date:** [April 29, 2016, 12:26pm UTC](https://forum.mattermost.com/t/api-to-get-private-messages/1388/4 "2016-04-29T12:26:28Z")

</div>

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](https://github.com/mattermost/platform/blob/master/webapp/utils/constants.jsx#L146) and the code that handles them on the web client is [here](https://github.com/mattermost/platform/blob/master/webapp/action_creators/websocket_actions.jsx#L106)

---

<div class="post-metadata">

**Author:** ![jayshree.rathod](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jayshree.rathod](https://forum.mattermost.com/u/jayshree.rathod)\
**Post date:** [April 30, 2016, 11:40am UTC](https://forum.mattermost.com/t/api-to-get-private-messages/1388/5 "2016-04-30T11:40:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hmhealey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/hmhealey/32/1915_2.png) [@hmhealey](https://forum.mattermost.com/u/hmhealey)\
**Post date:** [May 3, 2016, 12:26pm UTC](https://forum.mattermost.com/t/api-to-get-private-messages/1388/6 "2016-05-03T12:26:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jayshree.rathod](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jayshree.rathod](https://forum.mattermost.com/u/jayshree.rathod)\
**Post date:** [May 5, 2016, 5:21am UTC](https://forum.mattermost.com/t/api-to-get-private-messages/1388/7 "2016-05-05T05:21:45Z")

</div>

Hi,

Thanks. It’s working awesome.

Thanks,  
Jayshree.
