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

Create new Web Service to retrieve information about a badge (core_badges_get_badge)

XMLWordPrintable

    • MOODLE_405_STABLE
    • MOODLE_405_STABLE
    • MDL-82105-main
    • Hide
      1. As an admin, enable “Web services for mobile devices” on Site administration ► Advanced features
      2. Create a Token in the mobile app service for the admin use
        • Click on Site administration ► Server ► Web services ► Manage tokens
      3. Enable badges and course badges in advanced features
      4. Create a site level badge:
        • Add criteria, for example: Profile completion → First name
        • In the alert “This badge is currently not available to users. Enable access if you want users to earn this badge.” → Click in “Enable access” and Confirm. This will make your badge visible to users and allow them to start earning it.
      5. In the IRL you can see the parameter id, save it
      6. Check BadgeClass:
        • Replace the $id and the MOODLE_URL in the next URL and you can see the information of your badge: “MOODLE_URL/badges/badgeclass.php?id=$id”
      7. Next, you can do a CURL REST call simulating a WS client with the user administrator.
        • You need to replace the wstoken, id and the URL of your moodle instance
          curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_badges_get_badge&wstoken=$wstoken&id=$id' --compressed
        • Confirm that You receive your badge
      8. Now, run the CURL with an invalid id.
        • Check The Web Service return a warning “badgeawardnotfound”.
      9. Last, disable the global setting enablebadges, run the curl again
        • Check The Web Service return a warning “badgesdisabled”.
      Show
      As an admin, enable “Web services for mobile devices” on Site administration ► Advanced features Create a Token in the mobile app service for the admin use Click on Site administration ► Server ► Web services ► Manage tokens Enable badges and course badges in advanced features Create a site level badge: Add criteria, for example: Profile completion → First name In the alert “This badge is currently not available to users. Enable access if you want users to earn this badge.” → Click in “Enable access” and Confirm. This will make your badge visible to users and allow them to start earning it. In the IRL you can see the parameter id, save it Check BadgeClass: Replace the $id and the MOODLE_URL in the next URL and you can see the information of your badge: “MOODLE_URL/badges/badgeclass.php?id=$id” Next, you can do a CURL REST call simulating a WS client with the user administrator. You need to replace the wstoken, id and the URL of your moodle instance curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_badges_get_badge&wstoken=$wstoken&id=$id' --compressed Confirm that You receive your badge Now, run the CURL with an invalid id. Check The Web Service return a warning “badgeawardnotfound”. Last, disable the global setting enablebadges, run the curl again Check The Web Service return a warning “badgesdisabled”.

      This Web Service will help us to mimic the LMS behaviour of /badges/badgeclass.php?id=18 that is used to display a badge from the tags page.

      core_badges_get_badge: Retrieves a badge by id
      Parameters: id (the badge id)
      Returns: Badge information (using the badgeclass exporter/badges/classes/external/badgeclass_exporter.php)

      It should mimic the behaviour of /badges/badgeclass.php

      For reference (new recently integrated WS): badges/classes/external/get_user_badge_by_hash.php

            daniure Dani Ureña
            jleyva Juan Leyva
            Juan Leyva Juan Leyva
            Ilya Tregubov Ilya Tregubov
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days, 3 hours, 7 minutes
                2d 3h 7m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.