Search code examples
postmanmoodle-api

How to POST a request on Moodle using POSTMAN api tool


I want to create an API request in Postman that creates a category in Moodle. The following are the steps which I did in Moodle :

  1. Enabled Web service
  2. Created an External service and added core_course_create_categories function.
  3. Enabled REST protocol
  4. Created Token.

This is my POST URL: http://localhost/test/moodle/webservice/rest/server.php?username=admin&password=Password@1&service=mycustomservice&name=CustomCategory&parent=1&idnumber=CSTM1&description=Desc

Under Authorization tab, I have selected Bearer Token and added the Token from Moodle web service.

When I send the request, I am getting invalidtoken Invalid token - token not found error.

Can anyone please suggest a solution for this

Moodle version: 3.4.8 and Postman version 7.6.0

Thanks in advance.


Solution

  • You can not call API by GET Method. In postman you have to call the API using POST method. pass your token in form-data as wstoken. call your function as wsfunction.

    Check my Screenshot below. enter image description here