Invalid messageid, you don't have permissions to mark this message as read

Invalid messageid, you don't have permissions to mark this message as read

by Doug Stevens -
Number of replies: 1

Hi all, I'm writing a Power Automate Flow that will watch for unread moodle messages and send them to MS Teams for our teachers.  The only challenge is that after sending the message to Teams I want to mark it as read (so the script doesn't keep sending it).  Unfortunately when I send:

{
  "wstoken""stuff",
  "wsfunction""core_message_mark_message_read",
  "messageid""262105"  <<-- Returned from the id field of core_message_get_messages
}
 
it returns
 
<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="invalid_parameter_exception">
   <ERRORCODE>invalidparameter</ERRORCODE>
   <MESSAGE>Invalid parameter value detected</MESSAGE>
   <DEBUGINFO>Invalid messageid, you don't have permissions to mark this message as read</DEBUGINFO>
</EXCEPTION>
 
I've elevated the user attached to the token to the system administrator to no avail.  Any ideas?
 
Thanks in advance,
Doug
Average of ratings: -
In reply to Doug Stevens

Re: Invalid messageid, you don't have permissions to mark this message as read

by Doug Stevens -
Hmmm.... some more (unfortunate) info.

Looking at message/externallib.php line 2505, it looks like this functionality is baked in.

if ($message->useridto != $USER->id) {
throw new invalid_parameter_exception('Invalid messageid, you don\'t have permissions to mark this message as read');
}

This function needs to be run by the receiving user.