Messaging API

Messaging API

core_message_get_messages

This function retrieves messages for a user. You can get all messages sent to a user, or get the conversation between two specific users.

Let's review the POST parameters for this function:

  1. Parameters:
    • useridto= int (Required: The numeric ID of the user who received the messages.)
    • useridfrom= int (Optional: The numeric ID of the user who sent the messages. Defaults to 0, meaning 'from any user'.)
  2. Important Rule:
    • You must provide a specific user ID for at least one of the parameters. Setting both useridto and useridfrom to 0 is not permitted.

cURL Command Example 1 (Get all messages sent TO a user):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_message_get_messages" \
-d "useridto=123" \
-d "useridfrom=0"

cURL Command Example 2 (Get a conversation BETWEEN two users):

curl "https://courses.yoursite.com/webservice/rest/server.php?wstoken=XXXXXXXXXXXXXXX" \
-d "wsfunction=core_message_get_messages" \
-d "useridto=123" \
-d "useridfrom=456"