Hello, how are you?
I'm using the Moodle API to create courses in this way. To do this, I created an external service with the core_course_create_courses function enabled, and I granted permission to my user, everything is correct in that regard.
I make the API call from Postman like any other API calls I've done before that have worked. The endpoint is: https://my.domain/webservice/rest/server.php
As parameters, I pass my wstoken and the wsfunction, which is core_course_create_courses. Then, in the body, using form-data, I pass the values of my course as follows:
courses[0][fullname] -> Course created by API
courses[0][shortname] -> cursoapi
courses[0][categoryid] -> 1
I pass these values because they are the only mandatory ones according to the documentation. When I make this call, I get the following response:
{"eventname":"\\core\\event\\course_created","component":"core","action":"created","target":"course","objecttable":"course","objectid":"48","crud":"c","edulevel":1,"contextid":109,"contextlevel":50,"contextinstanceid":"48","userid":"2","courseid":"48","relateduserid":null,"anonymous":0,"other":{"shortname":"cursoapi","fullname":"Course created by API"},"timecreated":1700126604}
This response is already very different from all the responses I have received from other calls I have made (for example, I had to insert users, and it worked correctly).
However, I don't see any errors in the response, and the call gives me a status of 200 OK, so I assume the call is correct. But when I go to check if the course has been created in the interface, I cannot find this course. I have checked the logs, but there is nothing apart from the log of having called this service.
I have been investigating for a long time, and I cannot find anything similar to this, and I don't know why the course is not being created correctly. I have also checked the database, and there is no record with the data that I have assigned.
Thank you very much for your help.
(PD: I am using Moodle 4.2)