1

Some background

I am connecting external application (server) with Moodle through Web Services API.

  • First a user obtains web services token through a call to /login/token.php.
  • Above token can be used to call web services functions through /webservice/rest/server.php endpoint.

The problem

In some cases I need to provide userid, which I don't know, because /login/token.php does not return it.

Things I've tried

I searched through the Web Services api documentation and found core_session_time_remaining function. Documentation says it returns userid and timeremaining properties:

object {
userid int   //The current user id.
timeremaining int   //The number of seconds remaining in this session.
} 

The problem is, returned userid is always 0, irrelevant of what token was used to call this function. Is it a bug in Moodle, or am I using it wrong? How can I get userid?

1 Answer 1

0

did you ever tried using the core_webservice_get_site_info wsfunction?

I use it and works fine.

According to the docs: "Return some site info / user info / list web service functions" API Doc

1
  • This function seems to work correctly, thanks.
    – Anastazy
    Commented Jul 9, 2022 at 4:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.