|
| 1 | +--- |
| 2 | +title: Badges API |
| 3 | +tags: |
| 4 | + - API |
| 5 | + - Badges |
| 6 | +--- |
| 7 | +<!-- cspell:ignore Instructure's --> |
| 8 | + |
| 9 | +The Moodle Badges API facilitates the creation and management of site and course-specific badges, enabling their export to external Open Badges compliant platforms, often referred to as "backpacks". |
| 10 | + |
| 11 | +## Evolution of Open Badges |
| 12 | + |
| 13 | +The **Open Badges** standard, designed to recognize and verify learning achievements, has evolved significantly since its beginning. The **Mozilla Foundation** launched the initial version in 2012 with **Open Badges 1.0** and its "Backpack" platform. Over time, the standard matured, with **Open Badges 2.0** officially released by the **IMS Global Learning Consortium (now 1EdTech)** on April 12, 2018. |
| 14 | + |
| 15 | +Following the release of Open Badges 2.0, Mozilla announced the retirement of its Backpack program in late 2018. This led to a migration to **Concentric Sky's (now Instructure's) Badgr platform**, which started in August 2019. More recently, in April 2022, **Canvas LMS** acquired Concentric Sky, the creators of Badgr. |
| 16 | + |
| 17 | +While many providers support Open Badges 2.0, **Badgr offers a unique API implementation, inherited from Mozilla** (detailed at https://api.badgr.io/swagger-ui/index.html). Moodle directly supports this specific API. This is important because the Open Badges 2.0 specification defines the badge data itself, but not the protocol for interchanging badges. |
| 18 | + |
| 19 | +## Badges data (JSON) |
| 20 | + |
| 21 | +Each badge is represented as a JSON object with the following structure: |
| 22 | + |
| 23 | +```json title="Example Open Badge v2.0/v2.1 JSON" |
| 24 | +{ |
| 25 | + "@context": "https://w3id.org/openbadges/v2", |
| 26 | + "type": "BadgeClass", |
| 27 | + "id": "https://example.com/badges/12345", |
| 28 | + "name": "Example Badge", |
| 29 | + "description": "This badge represents an example achievement.", |
| 30 | + "image": "https://example.com/images/badge.png", |
| 31 | + "criteria": { |
| 32 | + "narrative": "To earn this badge, you must complete the example task." |
| 33 | + }, |
| 34 | + "issuer": { |
| 35 | + "type": "Issuer", |
| 36 | + "id": "https://example.com/issuers/67890", |
| 37 | + "name": "Example Issuer", |
| 38 | + "url": "https://example.com" |
| 39 | + } |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +Each version of Open Badges uses its own JSON schema to define the badge's data. Currently, Moodle supports **Open Badges 2.0 and 2.1**, which share the same schema. In the near future, it will also support **Open Badges 3.0**, which has a different schema. |
| 44 | + |
| 45 | +To manage these different versions and their unique requirements, each Open Badge version requires a specific folder structure containing its respective exporters. The structure is as follows: |
| 46 | + |
| 47 | +```none title="Folder structure for Open Badges exporters" |
| 48 | +├── local/backpack/ob/v2p0/ |
| 49 | +│ ├── assertion_exporter.php |
| 50 | +│ ├── badge_exporter.php |
| 51 | +│ ├── issuer_exporter.php |
| 52 | +│ ├── recipient_exporter.php |
| 53 | +│ ├── revoked_assertion_exporter.php |
| 54 | +``` |
| 55 | + |
| 56 | +The JSON files are generated by calling the exporters located in the respective version folders. They can be accessed from the badges/json/ folder, specified by the version number in the URL. For example, to access the Open Badges 2.0 JSON, you would use: |
| 57 | + |
| 58 | +```none title="Accessing Open Badges v2.0 assertion JSON" |
| 59 | +https://yourmoodlesite.com/badges/json/assertion.php?b=assertionhash&obversion=v2p0 |
| 60 | +``` |
| 61 | + |
| 62 | +## See also |
| 63 | + |
| 64 | +- [Open Badges Specification v2.0](https://www.imsglobal.org/spec/ob/v2p0) |
| 65 | +- [Open Badges Specification v2.1](https://www.imsglobal.org/spec/ob/v2p1) |
| 66 | +- [Open Badges Specification v3.0](https://www.imsglobal.org/spec/ob/v3p0) |
0 commit comments