Moodle / Totara | Null response on calling Plugin api from outside

|
| By Webner

Description: In one project we were invoking methods of a Moodle plugin from outside in the web app with the help of curl post requests. At the Moodle’s end, we have created a custom plugin and defined our methods in that. We are returning back json_encoded string from the plugin method. Once, while testing this functionality, we faced an issue that after calling the api method, we were getting null response after it was being decoded with json_decode. We were surprised because called operation was successfully performed at the Moodle end but when we were checking the response result it was null.

Solution: First we checked the response before applying the json_decode method and found that the returned json_encoded value by the method was correct but it was coming with one extra warning at api-end as shown in the below screenshot:
1

And we are using following code to decode the returned encoded json string:

$response = json_decode($response, true);

But the json_decode method could not decode the entire response with that warning message and result was null. Then we googled how can we check the debug status of the site for moodle/totara and found the way we can make that debug off so that it can stop returning unnecessary warnings in the response of any method call. For that, in moodle/totara, we have to navigate the link as follows:

Site Administration->Development->Debugging

The following screen will appear and make changes as shown here:

2

When we tested after making the above mentioned changes it worked properly.

Leave a Reply

Your email address will not be published. Required fields are marked *