IM REST Report V2

Message history

Currently, only the last 60 days of messages are saved. Addresses of The APIs are unified (note that unlike the Push API): https://report.im.jpush.cn/v2 ,which improves the stability and speed of the overall query compared to V1 V2, and also increases the maximum number of pages for a query

HTTP Authentication

Authentication uses the HTTP Basic mechanism, that is, a field (Key/Value pair) Authorization: Basic base64_auth_string is added in the HTTP Header (header). The generation algorithm of base64_auth_string is: base64(appKey:masterSecret) That is, adding a colon to appKey, plus masterSecret Assembled strings, and then do a base64 conversion.

Tips:

The URL passed to the JMessage via this interface needs to be processed by the URL Encode, for example, spaces in the time format need to be escaped as %20.

Get Message

  1. GET /messages?count=1000&begin_time={begin_time}&end_time={end_time}

Example Request

Request Header

  1. GET /messages?count=500&begin_time=2015-11-02 10:10:10&end_time=2015-11-02 10:10:12 (第一次请求)
  1. GET /messages?cursor=KSDKF34UISOCGAASD (第n次获取 n>1

Request Body

  • N/A

Request Params

  • count (required): The total number of entries per query. Up to 1000 at a time
  • begin_time (required): Start time of the record. Format yyyy-MM-dd HH:mm:ss. Set the filter condition greater than or equal to the begin time
  • end_time (required): End time of the record. Format yyyy-MM-dd HH:mm:ss. Set the filter condition smarter or equal to end time
  • The maximum range between begin_time end_time must not exceed 7 days.
  • cursor: If there is data after the first request, it will return a cursor to get the following message (valid time of cursor is 120s. Need to re-pass the first request cursor after it is expired)
  • Queried messages are sorted in ascending order by sending time

Example Response

Response Header

  1. HTTP/1.1 200
  2. Content-Type: application/json; charset=utf-8

Response Data

  1. {
  2. "total": 3000, "cursor":"APSK234ASDKQWE", "count": 1,
  3. "messages": [
  4. { "target_type": "single",
  5. "msg_type": "text",
  6. "target_name": "",
  7. "target_id": "10010648",
  8. "from_id": "868802000386631",
  9. "from_name": "868802000386631",
  10. "from_type": "user",
  11. "from_platform": "a",
  12. "msg_body": {
  13. "text": "text",
  14. "extras": { }
  15. },
  16. "create_time": 1446016259,
  17. "version": 1,
  18. "msgid": 13242735,
  19. "msg_level" : 0, // 0代表应用内消息 1代表跨应用消息
  20. "msg_ctime" : 1466866468352 // 服务器接收到消息的时间,单位毫秒
  21. }
  22. ]
  23. }

Get user messages

  1. GET /users/{username}/messages?count=1000&begin_time={begin_time}&end_time={end_time}

Example Request

Request Header

  1. GET /users/caiyh/messages?count=500&begin_time=2015-11-02 10:10:10&end_time=2015-11-02 10:10:12 第一次请求)
  1. GET /users/{username}/messages?cursor=KSDKF34UISOCGAASD (第n次获取 n>1

Request Body

  • N/A

Request Params

  • Query messages are sorted in ascending order by sending time
  • count (required): The total number of entries per query. Up to 1000 at a time
  • begin_time (required): Start time of the record. Format yyyy-MM-dd HH:mm:ss. Set the filter condition greater than or equal to the begin time
  • end_time (required): End time of the record. Format yyyy-MM-dd HH:mm:ss. Set the filter condition smarter or equal to end time
  • The maximum range between begin_time end_time must not exceed 7 days.
  • cursor: If there is data after the first request, it will return a cursor to get the following message (valid time of cursor is 120s. Need to re-pass the first request cursor after it is expired)
  • Queried messages are sorted in ascending order by sending time

Example Response

Response Header

  1. HTTP/1.1 200
  2. Content-Type: application/json; charset=utf-8

Response Data

  1. {
  2. "total": 3000, "cursor":"APSK234ASDKQWE", "count": 1,
  3. "messages": [
  4. { "target_type": "single",
  5. "msg_type": "text",
  6. "target_name": "",
  7. "target_id": "10010648",
  8. "from_id": "868802000386631",
  9. "from_name": "868802000386631",
  10. "from_type": "user",
  11. "from_platform": "a",
  12. "from_appkey": "4f7aef34fb361292c566a1cd",
  13. "target_appkey": "4f7aef34fb361292c566a1cd",
  14. "msg_body": {
  15. "text": "text",
  16. "extras": { }
  17. },
  18. "create_time": 1446016259,
  19. "version": 1 ,
  20. "msgid": 13242735,
  21. "msg_level" : 0 // 0代表应用内消息 1代表跨应用消息
  22. "msg_ctime" : 1466866468352 // 服务器接收到消息的时间,单位毫秒
  23. }
  24. ]
  25. }

Get group messages

  1. GET /groups/{gid}/messages?count=1000&begin_time={begin_time}&end_time={end_time}

Example Request

Request Header

  1. GET /groups/10055201/messages?count=500&begin_time=2015-11-02 10:10:10&end_time=2015-11-02 10:10:12 第一次请求)
  1. GET /groups/10055201/messages?cursor=KSDKF34UISOCGAASD (第n次获取 n>1

Request Body

  • N/A

Request Params

  • count (required): The total number of entries per query. Up to 1000 at a time
  • begin_time (required): Start time of the record. Format yyyy-MM-dd HH:mm:ss. Set the filter condition greater than or equal to the begin time
  • end_time (required): End time of the record. Format yyyy-MM-dd HH:mm:ss. Set the filter condition smarter or equal to end time
  • The maximum range between begin_time end_time must not exceed 7 days.
  • cursor: If there is data after the first request, it will return a cursor to get the following message (valid time of cursor is 120s. Need to re-pass the first request cursor after it is expired)
  • Queried messages are sorted in ascending order by sending time

Example Response

Response Header

  1. HTTP/1.1 200
  2. Content-Type: application/json; charset=utf-8

Response Data

  1. {
  2. "total": 1,
  3. "cursor": "02838264C47BA022DE545AF2D013B59A",
  4. "count": 1,
  5. "messages": [
  6. {
  7. "set_from_name": 1,
  8. "from_platform": "a",
  9. "target_name": "",
  10. "msg_type": "text",
  11. "version": 1,
  12. "target_id": "10055201",
  13. "from_appkey": "4f7aef34fb361292c566a1cd",
  14. "from_name": "custom name nnn",
  15. "from_id": "ppppp",
  16. "msg_body": {
  17. "text": "hehe",
  18. "extras": {}
  19. },
  20. "create_time": 1490930940,
  21. "from_type": "user",
  22. "target_appkey": "",
  23. "target_type": "group",
  24. "msgid": 287090485,
  25. "msg_ctime": 1490930941708,
  26. "msg_level": 0
  27. }
  28. ]
  29. }

Get chat room messages

  1. GET /chatrooms/{chatroomid}/messages?count=100&begin_time={begin_time}&end_time={end_time}

Example Request

Request Header

  1. GET /chatrooms/{chatroomid}/messages?count=100&begin_time=2017-11-02 10:10:10&end_time=2017-11-02 10:10:12 第一次请求)
  1. GET /chatrooms/{chatroomid}/messages?cursor=KSDKF34UISOCGAASD (第n次获取 n>1

Request Body

  • N/A

Request Params

  • count (required): The total number of entries per query. Up to 1000 at a time
  • begin_time (required): Start time of the record. Format yyyy-MM-dd HH:mm:ss. Set the filter condition greater than or equal to the begin time
  • end_time (required): End time of the record. Format yyyy-MM-dd HH:mm:ss. Set the filter condition smarter or equal to end time
  • The maximum range between begin_time end_time must not exceed 7 days.
  • cursor: If there is data after the first request, it will return a cursor to get the following message (valid time of cursor is 120s. Need to re-pass the first request cursor after it is expired)
  • Queried messages are sorted in ascending order by sending time

Example Response

Response Header

  1. HTTP/1.1 200
  2. Content-Type: application/json; charset=utf-8

Response Data

  1. {
  2. "total": 1,
  3. "cursor": "02838264C47BA022DE545AF2D013B59A",
  4. "count": 1,
  5. "messages": [
  6. {
  7. "set_from_name": 1,
  8. "from_platform": "a",
  9. "target_name": "",
  10. "msg_type": "text",
  11. "version": 1,
  12. "target_id": "10055201",
  13. "from_appkey": "4f7aef34fb361292c566a1cd",
  14. "from_name": "custom name nnn",
  15. "from_id": "ppppp",
  16. "msg_body": {
  17. "text": "hehe",
  18. "extras": {}
  19. },
  20. "create_time": 1490930940,
  21. "from_type": "user",
  22. "target_appkey": "",
  23. "target_type": "chatroom",
  24. "msgid": 287090485,
  25. "msg_ctime": 1490930941708,
  26. "msg_level": 0
  27. }
  28. ]
  29. }

Statistics interface (vip exclusive interface)

User Statistics

  1. GET /statistic/users?time_unit={time_unit}&start={start}&duration={duration}

Example Request

Request Header

  1. GET /statistic/users?time_unit=DAY&start=2017-03-01&duration=3

Request Body

  • N/A

Request Params

  • time_unit (required): query dimension, currently only DAY
  • start (required): The starting time, time_unit is DAY when the format is yyyy-MM-dd
  • duration (required): The duration of the request, up to 60 days for DAY
  • Statistics only save records for the last 60 days

Example Response

Response Header

  1. HTTP/1.1 200
  2. Content-Type: application/json; charset=utf-8

Response Data

  1. [
  2. {
  3. "active_users": 29,
  4. "total_users": 66938,
  5. "send_msg_users": 7,
  6. "new_users": 2,
  7. "date": "2017-03-01"
  8. },
  9. {
  10. "active_users": 29,
  11. "total_users": 66941,
  12. "send_msg_users": 10,
  13. "new_users": 3,
  14. "date": "2017-03-02"
  15. },
  16. {
  17. "active_users": 22,
  18. "total_users": 66943,
  19. "send_msg_users": 3,
  20. "new_users": 2,
  21. "date": "2017-03-03"
  22. }
  23. ]
  • active_user: active users
  • total_users: total users
  • send_msg_users: number of users who sent the message
  • new_user: new users

Message Statistics

  1. GET /statistic/messages?time_unit={time_unit}&start={start}&duration={duration}

Example Request

Request Header

  1. GET /statistic/messages?time_unit=DAY&start=2017-03-01&duration=2

Request Body

  • N/A

Request Params

  • time_unit (required): query dimension. There are currently three dimensions of HOUR, DAY, MONTH to choose from
  • start (required:) Start time. Format is yyyy-MM-dd HH when time_unit is HOUR, yyyy-MM-dd when time_unit is DAT, and yyyy-MM when time_unit is MONTH.
  • duration (required): duration of the request. HOUR only supports statistics for the day of the query, maximum for DAY is 60 days, MONTH is two months
  • Statistics only save records for the last 60 days

Example Response

Response Header

  1. HTTP/1.1 200
  2. Content-Type: application/json; charset=utf-8

Response Data

  1. {
  2. "send_msg_stat": [
  3. {
  4. "time": "2017-03-01",
  5. "group_send_msg": 89,
  6. "single_send_msg": 170916
  7. },
  8. {
  9. "time": "2017-03-02",
  10. "group_send_msg": 306,
  11. "single_send_msg": 170944
  12. },
  13. {
  14. "time": "2017-03-03",
  15. "group_send_msg": 71,
  16. "single_send_msg": 170782
  17. }
  18. ],
  19. "group_msg_stat": {
  20. "txt_msg": 425,
  21. "image_msg": 39,
  22. "voice_msg": 1,
  23. "other_msg": 1
  24. },
  25. "single_msg_stat": {
  26. "txt_msg": 512633,
  27. "image_msg": 7,
  28. "voice_msg": 1,
  29. "other_msg": 1
  30. }
  31. }
  • send_msg_stat : statistics of sending message
  • send_msg_stat->group_send_msg : 群组发送消息数number of group send messages
  • send_msg_stat->single_send_msg : 单聊发送消息数number of single chat messages
  • group_msg_stat :群组消息类型统计group message type statistics
  • group_msg_stat->txt_msg : 群组文本消息条数number of group text messages
  • group_msg_stat->image_msg : 群组图片消息条数number of group image messages
  • group_msg_stat->voice_msg : 群组语音消息条数number of group voice messages
  • group_msg_stat->other_msg : 群组其他类型消息条数number of other types of messages in the group
  • single_msg_stat :单聊消息类型统计single chat message type statistics
  • single_msg_stat->txt_msg : 单聊文本消息条数The number of single-talk text messages
  • single_msg_stat->image_msg : 单聊图片消息条数Number of single chat picture messages
  • single_msg_stat->voice_msg : 单聊语音消息条数number of single chat voice messages
  • single_msg_stat->other_msg : 单聊其他类型消息条数single chat other types of messages

Group Statistics

  1. GET /statistic/groups?time_unit={time_unit}&start={start}&duration={duration}

Example Request

Request Header

  1. GET /statistic/groups?time_unit=DAY&start=2017-03-01&duration=3

Request Body

  • N/A

Request Params

  • time_unit (required): query dimension, currently only DAY
  • start (required):starting time, format is yyyy-MM-dd when time_unit is DAY
  • duration (required): duration of the request, up to 60 days for DAY
  • Statistics only save records for the last 60 days

Example Response

Response Header

  1. HTTP/1.1 200
  2. Content-Type: application/json; charset=utf-8

Response Data

  1. [
  2. {
  3. "date": "2017-03-01",
  4. "active_group": 5,
  5. "total_group": 5,
  6. "new_group": 3
  7. },
  8. {
  9. "date": "2017-03-02",
  10. "active_group": 9,
  11. "total_group": 9,
  12. "new_group": 2
  13. },
  14. {
  15. "date": "2017-03-03",
  16. "active_group": 3,
  17. "total_group": 3,
  18. "new_group": 0
  19. }
  20. ]
  • active_user:active users
  • total_users: total users
  • send_msg_users : number of users who sent the message
  • new_user: new users

参考