1

I am trying to create a category in moodle making api call from postman

API Endpoint: http://localhost/MyMoodle/webservice/rest/server.php

Method: POST

Payload: Selected x-www-form-urlencoded

wstoken:<token>
wsfunction:core_course_create_categories
moodlewsrestfomat:json
categories[0][name]:Custom Cat 1
categories[0][parent]:0
categories[0][idnumber]:1
categories[0][description]:CustomCatdescription

getting below error

<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="invalid_parameter_exception">
    <ERRORCODE>invalidparameter</ERRORCODE>
    <MESSAGE>Invalid parameter value detected</MESSAGE>
</EXCEPTION>
Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104
  • You can test a web service by going to Site Administration > Development > Web service test client - double check your parameters there - also check the web service is set up correctly via Site Administration > Server > Overview – Russell England Feb 08 '23 at 17:04

1 Answers1

0

Based on the error and the test parameters, I'd guess it's one of these issues:

  1. Postman isn't encoding the spaces, and Moodle doesn't like that. Try replacing the spaces in your category name with %20
  2. The idnumber is not unique. Check that a category with that idnumber doesn't already exist.

Also, I just wanted to note that you can also test the Moodle API directly in your browser. This can be a good way to make sure there's not an issue with any of your credentials or permissions. Just navigate to a url like this:

http://localhost/MyMoodle/webservice/rest/server.php?moodlewsrestformat=json&wstoken=<token>&wsfunction=core_course_create_categories&categories[0][name]=Custom%20Cat%201&categories[0][parent]=0&categories[0][idnumber]=1&categories[0][description]=CustomCatdescription
TzeraFNX
  • 121
  • 6