Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-57923

New Web Service mod_data_add_entry

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. Create in a course a database with 3 fields: checkbox (options A, B, C) being a required field, number field not required and url field not required.
      2. Enable "Mobile services": Site administration ► Mobile app ► Mobile settings
      3. Create a Token in the mobile app service for one student in the course:
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      4. Next, you can do a CURL REST call simulating a WS client with the student token.
        • You need to replace the wstoken, databaseid (your database id), the URL of your moodle instance and replacing data[0][fieldid]=113 with your checkbox field id (from database or inspecting the form), [fieldid]=114 with your URL field id, and [fieldid]=115 with your numeric field id.

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'databaseid=24&wsfunction=mod_data_add_entry&wstoken=12a2a65aeea2a177055e233f9e303218&moodlewssettingfilter=true&data[0][fieldid]=113&data[0][subfield]=&data[0][value]=["A","B"]&data[1][fieldid]=114&data[1][subfield]=0&data[1][value]="https:\/\/moodle.org"&data[2][fieldid]=115&data[2][subfield]=&data[2][value]="5"' | python -m "json.tool"

      5. Confirm that a new entry is created with values A and B for the checkbox field, 5 for the numeric, and https://moodle.org for the url one
      6. Now, if you remove &data[0][fieldid]=113&data[0][subfield]=&data[0][value]=["A","B"] from the query and execute the curl request again you should see an error indicating that the field is required
      7. If you replace all the data[x] with &data[0][fieldid]=0&data[0][subfield]=&data[0][value]= you should get a ""You did not fill out any fields!"
      8. Optionally you can check additional things like setting a read only period or limiting the maximimun number of entries a user can create to check that in those cases the WS return errors
      9. If you want to play with other fields please review the unit tests in the patch where you will se the format for other field types
      Show
      Create in a course a database with 3 fields: checkbox (options A, B, C) being a required field, number field not required and url field not required. Enable "Mobile services": Site administration ► Mobile app ► Mobile settings Create a Token in the mobile app service for one student in the course: Click on Site administration ► Plugins ► Web services ► Manage tokens Next, you can do a CURL REST call simulating a WS client with the student token. You need to replace the wstoken, databaseid (your database id), the URL of your moodle instance and replacing data [0] [fieldid] =113 with your checkbox field id (from database or inspecting the form), [fieldid] =114 with your URL field id, and [fieldid] =115 with your numeric field id. curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'databaseid=24&wsfunction=mod_data_add_entry&wstoken=12a2a65aeea2a177055e233f9e303218&moodlewssettingfilter=true&data [0] [fieldid] =113&data [0] [subfield] =&data [0] [value] = ["A","B"] &data [1] [fieldid] =114&data [1] [subfield] =0&data [1] [value] ="https:\/\/moodle.org"&data [2] [fieldid] =115&data [2] [subfield] =&data [2] [value] ="5"' | python -m "json.tool" Confirm that a new entry is created with values A and B for the checkbox field, 5 for the numeric, and https://moodle.org for the url one Now, if you remove &data [0] [fieldid] =113&data [0] [subfield] =&data [0] [value] = ["A","B"] from the query and execute the curl request again you should see an error indicating that the field is required If you replace all the data [x] with &data [0] [fieldid] =0&data [0] [subfield] =&data [0] [value] = you should get a ""You did not fill out any fields!" Optionally you can check additional things like setting a read only period or limiting the maximimun number of entries a user can create to check that in those cases the WS return errors If you want to play with other fields please review the unit tests in the patch where you will se the format for other field types
    • Affected Branches:
      MOODLE_32_STABLE
    • Fixed Branches:
      MOODLE_33_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-57923-master

      Description

      Adds an entry

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jleyva Juan Leyva
                Reporter:
                jleyva Juan Leyva
                Peer reviewer:
                Pau Ferrer
                Integrator:
                Eloy Lafuente (stronk7)
                Tester:
                Eloy Lafuente (stronk7)
                Participants:
                Component watchers:
                Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Juan Leyva, Jake Dallimore, Jun Pataleta
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  15/May/17