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:
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:
The following screen will appear and make changes as shown here:
When we tested after making the above mentioned changes it worked properly.