Getting redirected to login page when using REST Web Service

Getting redirected to login page when using REST Web Service

by Agustín Rodríguez -
Number of replies: 1

Hi! 


The Context:

I have a Moodle 3.x installation and right now I'm trying to integrate an external system to it. This system needs to fetch users and courses so I want to provide a web service (preferably rest) in order to allow his developers to fetch that info.


The Problem:

I followed this steps: https://docs.moodle.org/dev/Creating_a_web_service_client in order to enable the web service, so I created a user, with Manual Authentication, then a role, assigned that role to the created user, after that I created the external service, assigned the necessary capabilities, etc, etc and finally tested the web service using the tool provided in the Overview page of Web Services plugin:  http://[hostname]/admin/webservice/testclient.php. It works! But here is the problem: When I try to use it from my external system (Using the curl.php script found here: https://github.com/moodlehq/sample-ws-clients), or even using a REST client (Insomnia) I get redirected to the login page instead of receiving the REST operation result. The URL that I'm using to call the REST service is: http://[hostname]/webservice/rest/server.php?wstoken=[token]&wsfunction=[function]&moodlewsrestformat=json


What I'm doing wrong? Could you help me please?


Thanks

Average of ratings: -
In reply to Agustín Rodríguez

Re: Getting redirected to login page when using REST Web Service

by Agustín Rodríguez -

Just in case that someone has the same problem: I was trying to use the IP address of the server as a hostname and it seems that (at least my Moodle installation) Moodle was redirecting me to the hostname like address. Changing the IP Address for the hostname in the [hostname] part of the url solved my problem.


Regards!