Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[RELEASED] Moodle API

Discussion in 'Assets and Asset Store' started by bdovaz, Dec 26, 2017.

  1. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016

    Moodle API providing Scorm 1.2 and 2004 integration. It implements all common and most used features available.

    ★ Ever wanted to integrate Scorm tracking options in a VR simulation developed with Oculus or HTC Vive?
    ★ Ever wanted to integrate Scorm tracking options in a standalone (Windows, Mac, Linux) or mobile (Android, iOS) application?

    This is your answer. You will be able to integrate it within minutes.

    Asset Store link

    https://assetstore.unity.com/packages/tools/integration/moodle-api-107893

    Online documentation


    https://docs.google.com/document/d/1XcRLuIlRh8EjciO7Girzj0lDk88JU4AjfDnja-2rzTY/


    Supported Platforms

    It should work on any platform that supports “UnityWebRequest” class.

    Features

    • Supports Moodle 3.0+ (some endpoints may require a greater version).
    • Initial implementation it’s Scorm oriented so if you need any endpoint that it’s not available yet, I can implement it really fast.

    • Full object oriented API (you don’t deserialize anything, it’s already done it for you).

    • C# Source code included.

    • Documentation available.

    • Easy integration to your Unity project.

    • Well organized and structured code.

    • Event based. Example: OnScormTracksInserted(MoodleAPI sender, uint[] trackIds)

    • Fully testable in editor: You can also log Moodle original endpoint url and JSON response.

    • Examples available. You can find editor test runner tests that shows how to use the available API.

    • Requires Unity 5.3+ (by default uses UnityWebRequest) but you can make it 5.0, 5.1, 5.2 backwards compatible implementing:
      • IWebRequest: Interface to make requests. You can use Best HTTP that is backwards compatible.
      • IWebRequestFactory: Interfaces that creates requests.
     
    Last edited: Apr 3, 2020
  2. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    It has been approved!
     
  3. coverpage

    coverpage

    Joined:
    Mar 3, 2016
    Posts:
    385
    This is interesting. Correct me if I'm wrong, but doesn't SCORM require the application to run inside moodle itself. So it can't update the parameters remotely outside of moodle.
     
  4. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Normally it is but Moodle exposes in it's official REST API some endpoints to overcome this limitation. It's really nice.

    So as you can see you can run your application and set Scorm tracks remotely without any problems.
     
  5. phatpixels

    phatpixels

    Joined:
    Sep 18, 2013
    Posts:
    9
    This is so great!!.....will there be a step by step how to video to implement this?..... for those who are new to developing unity training modules that need to be scorm tracked.
     
    skudgee likes this.
  6. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    What don't you understand? Did you read my docs? I think that it's well explained. There are some code examples with comments trying to explain them step by step.

    Ask specific questions and I will try to answer them.
     
  7. HenrikLSP

    HenrikLSP

    Joined:
    Jun 7, 2017
    Posts:
    1
    Can you tell me whether the Moodle API can be used to achieve what I need? I am new to Moodle, so the technical API specifications don't tell me what I can and cannot do with it.

    I have a set of Unity games and I would like to organize them as resources in an LMS (and Moodle looks like a good choice), so that a student can go through a course and access the Unity games in the same way as any other course material. Preferably the Unity game should be able to read the name of the logged in Moodle user and display it in-game. When the user completes the game, it notifies Moodle to mark it as completed, so that the user and course admin can track progress through the course.

    Can the Moodle API be used to do this?
    If so, how do I configure the Moodle course to include the Unity game as a course resource/activity?
     
  8. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Yes as you said you can:

    1. Read logged in user details.
    2. Track user progress across a course.

    In order to achieve that you need to create a course with a scorm type activity and once you have that and you have the correct permissions for that user in that course you can start using the API.
     
  9. BilderBoy

    BilderBoy

    Joined:
    Sep 4, 2018
    Posts:
    1
    Good evening,
    I am quite new to the e-learning business and therefore: Please dont get mad if I ask seemingly stupid questions.
    First I would like to know if I can develop what is going to be my SCORM package with BOLT? Then, can interactive 3D content also be content of a with this Pugin exported content?
    Thank you for helping me and make me understand the whole topic better!
    Best regards,
    BilderBoy
     
    Last edited: Sep 17, 2018
  10. NiallT

    NiallT

    Joined:
    Sep 22, 2018
    Posts:
    51
    Hi,
    I've just purchased the asset, but when I import it into a project I immediate get hit with a bunch of errors saying NUnit, TestTools, UnityTest and UnityTestAttribute don't exist (on both 2018.38 and 2019.1.4). There's nothing about this in the documentation that I can see, but because it seems to be just for testing I've deleted the test folder and it looks like I can continue. However, I suspect this is the sort of thing that will confuse a lot of less technical users, including a lot of teachers looking to write their own edtech.
     
  11. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Thanks, I will update the docs and the asset.
     
  12. NiallT

    NiallT

    Joined:
    Sep 22, 2018
    Posts:
    51
    Thanks. I'm a bit baffled with the asset, to be honest. The documented API doesn't even tell me how to log attempts and values. All I want to do is run a simple quiz and log the answers given, which I've been doing before now in JavaScript with no problems, but the API reference for this asset doesn't include anything I recognise as part of the basic SCORM API (e.g. GetValue and SetValue) and there's no example that does this in the package or documentation.
     
  13. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Have you looked at the example in the documentation?

    It is a complete example of how to log in with a user and save an attempt with its corresponding score and status.

    Also in the "Tests" folder that you have removed you have in "MoodleApiTest.Scorm.cs" many examples on how to use the API.
     
  14. NiallT

    NiallT

    Joined:
    Sep 22, 2018
    Posts:
    51
    Hmmm... so it appears the documentation in the package is missing the longer example that your online copy has -- the package only has the basic example which does nothing other than log a user in.

    I'm a programmer by background, and I suspect a lot of people who aren't coders (people building with no-code solutions like Fungus etc) would benefit from a lot more support -- at a minimum I'd say an example of a one-question quiz that logs the answer given would help a lot.
     
  15. NiallT

    NiallT

    Joined:
    Sep 22, 2018
    Posts:
    51
    Am I right in saying that the asset only lets you log complete attempts at SCORM activities, and not individual events as and when they arise? In SCORM packages I've written directly in HTML5, I've logged individual questions with SetValue, but the only thing I can see in your code that offers access to individual data items is the dictionary in the InsertScormTracks() method, which stores an entire activity session (attempt), not a single event.
     
  16. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Sorry for that.

    In the "InsertScormTracksAdvanced" method that it's in the "Tests" folder you can see an example using Scorm API objectives that it's what you want.

    My asset implements the Scorm related Moodle's REST API and there is only one function for that and describes as: "Saves a scorm tracking record."

    As you can see I'm just using the API and I can't do anything that it's not exposed by the API.

    If you have more questions please ask them without any problem.
     
  17. NiallT

    NiallT

    Joined:
    Sep 22, 2018
    Posts:
    51
    Fair enough. It might be worth adding a link in the documentation to a good tutorial on the REST API -- I personally came to the asset via a search for a SCORM asset, then I saw you had the Moodle-specific one too. I've never looked at the Moodle REST API before -- I didn't even know it existed until I saw your asset! I suspect a lot of people interested in the asset would benefit from being pointed in the right direction..
     
  18. NiallT

    NiallT

    Joined:
    Sep 22, 2018
    Posts:
    51
    Thanks for the info so far.

    I've been working through the code to try to work out how to do what I need, and there are two things I can't work out for myself.

    1) In order to add a new attempt at a previously attempted SCORM, I need to call GetScormAttemptCount, but I have to specify a user ID, but I can't see how to get the ID of the currently logged in user.

    2) I'm attempting to update interactions in the following code
    Code (CSharp):
    1.     public void TestProc()
    2.     {
    3.                 result = new Dictionary<string, string>() {
    4.                         { "cmi.core.lesson_location", "7" },
    5.                         { "cmi.core.lesson_status", "completed" },
    6.                         { "cmi.core.score.min", "0" },
    7.                         { "cmi.core.score.max", "100" },
    8.                         { "cmi.core.score.raw", "60" },
    9.                         { "cmi.suspend_data", "test data" },
    10.                         { "cmi.core.session_time", "PT1H10M25S" },
    11.                         { "cmi.interactions.0.id","0" },
    12.                         { "cmi.interactions.0.type","true-false" },
    13.                         { "cmi.interactions.0.time", "00:00:00.00" },
    14.                         { "cmi.interactions.0.student_response", "true" },
    15.                         { "cmi.interactions.0.result", "correct" },
    16.                         { "cmi.interactions.0.latency", "00:00:01.25"},
    17.                         { "cmi.interactions.1.id","1" },
    18.                         { "cmi.interactions.1.type","fill-in" },
    19.                         { "cmi.interactions.1.time", "00:00:00.00" },
    20.                         { "cmi.interactions.1.student_response", "car" },
    21.                         { "cmi.interactions.1.result", "correct" },
    22.                         { "cmi.interactions.1.latency", "00:00:01.25"}
    23.                     };
    24.          
    25.             api.InsertScormTracks(1, ++attemptCount, result);
    26.     }
    27.  
    (Log on and count lookup is currently done in Start and I've hardcoded the user ID in my call to GetScormAttemptCount for the purposes of testing.)

    Unfortunately when I look at the SCORM interactions report in Moodle, I can see columns for interaction 0 only ("Question 0", "Response 0", "Right answer 0" and "Result 0") and they're all showing up as empty. Am I doing something wrong with the API, or is this likely to be a configuration problem with my Moodle instance?

    Gracias de nuevo,
    Niall.
     
  19. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Check "MoodleApiTest.Scorm.cs" script and "GetScormAttemptCount" method. You will see that you need "GetUser" method and "OnUserDetailsRetrieved" event.

    I don't understand, it should work. Interactions are the only thing that doesn't work, right? As you can see my tests are using objectives not interactions but it should be the same.

    Check "EndpointLogEnabled" bool and paste the complete url in the browser to see the result you get. As you'll see the query format it's always the same format for all values, it's really weird if it doesn't work only for interactions.
     
  20. SecretAnorak

    SecretAnorak

    Joined:
    Mar 19, 2014
    Posts:
    177
    Just before I purchase, I have a couple of questions...

    1 - Does this work with Unity 2019.x,... if not, what is the latest version I can use?

    2 - What is the difference between this and your other asset "SCORM API" in term of use with moodle

    Thanks in advance
     
  21. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    It should. There is no "exotic" code. In case you find some problem I will fix it and update the asset without any problem.

    Scorm API:
    - Works on WebGL (= only works on this platform) exclusively. This is a limitation imposed by Scorm standard (it's web based) and not my asset itself.
    - Works on any LMS supporting Scorm 1.2/2004 (Moodle, Docebo, Cornerstone, ...).

    Moodle API:
    - Works on any Unity platform supporting UnityWebRequest.
    - Works on Moodle (= only works on this LMS) because it uses Moodle's specific API.
     
  22. SecretAnorak

    SecretAnorak

    Joined:
    Mar 19, 2014
    Posts:
    177
    Thanks for the fast response, exactly what I was after.

    Sold...! :D
     
  23. SecretAnorak

    SecretAnorak

    Joined:
    Mar 19, 2014
    Posts:
    177
    I have a small problem, 27 error messages when I import the package into a WebGL project (Unity 2019.1.1)

    upload_2019-9-6_13-24-6.png
     
    Last edited: Sep 6, 2019
  24. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    You only need to remove Test folder. They're just unit tests.
     
  25. SecretAnorak

    SecretAnorak

    Joined:
    Mar 19, 2014
    Posts:
    177
  26. skudgee

    skudgee

    Joined:
    Jun 17, 2015
    Posts:
    5
    Hello there, I've just purchased this asset and it seems pretty helpfull. so thanks for that.
    Otherwise I have to say I"m stuck with the "setup guid" don't you know any "step to step" tuto to setup correcly ?
     
  27. skudgee

    skudgee

    Joined:
    Jun 17, 2015
    Posts:
    5
    I would be awesome !
     
  28. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Have you read the online docs? There are instructions in how to setup Moodle.
     
  29. Qneuroindia

    Qneuroindia

    Joined:
    Nov 13, 2014
    Posts:
    4
    Hi,

    I've purchased the moodle api and tried gettoken and get user both are working fine but when I called getscorms it returns Response: {"scorms":[],"warnings":[]}.

    Am I missing something. Please help me how to resolve this.

    Thanks.
     
  30. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    I understand that you have created a course with Scorm type activities in Moodle, right? That's the first thing to check.
     
  31. prashantsavalia

    prashantsavalia

    Joined:
    Apr 22, 2019
    Posts:
    6
    I've been digging into SCORM and 3D gaming. I want to build a very simple first person exploration game where the player has to look as a certain number of items in order to pass to the next level. I envision 3 levels. Once the player completes the 3rd level, I want to have the game set the player as complete or passed in the LMS. Is there a simple way to do this for a proof of concept in Unity using SCORM 1.2? I have the levels build and the game manager in place, but when the user completes the 3rd level, I can't seem to figure out the correct line of code to insert to get it to mark the user complete in the LMS. I'm using Moodle (via localhost) as my LMS. It plays just fine, just doesn't mark them complete after the 3rd level. Any thoughts?
     
  32. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Are you using my asset? Please, make concrete questions with code if it's possible.
     
  33. anat712

    anat712

    Joined:
    May 5, 2020
    Posts:
    7
    Hey,
    First of all, thanks a lot for making this tool, it looks so useful!
    Before I download it I wanted to ask, we are using a program which is very similar to moodle and works with scrom. The only problem is that it's all offline, using an internal network (sorry if I'm not using the correct terms, English is my second language).
    Do you think I will still be able to use this tool?
     
  34. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    This asset is for Moodle LMS only, it will not work on other LMS.
     
  35. smiley_face_

    smiley_face_

    Joined:
    Apr 22, 2018
    Posts:
    1
    Hey,
    I'm trying to understand how to integrate unity into moodle and am not very familiar with moodle so forgive me if this is a stupid question. I'm really not sure how to begin using this API so to test out your basic example in the documentation would I simply copy and paste it into a function and it will work or will something else be required? because by just doing that I was getting a null reference exception.
     
  36. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Please read online documentation.
     
  37. Simango

    Simango

    Joined:
    Mar 31, 2020
    Posts:
    1
    Hi,
    Is the asset still working on unity 2019 and Moodle 3 ?
    I need to know before buying and beginning to work with it.
    Thank you.
     
  38. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Of course, also in 2020.x.
     
    Simango likes this.
  39. reynurstudio

    reynurstudio

    Joined:
    Feb 5, 2021
    Posts:
    1
    good day...
    today i purchase your asset.. its so asshamed that as beginner i really dont understand the documentation. like where and how i add component to unity configuration. how i use the basic example..
    so if you concern. please just make step by step process from importing the asset until deployment...my project need to finished in 2 days

    pleassseeeeee


    and one more thing in package content tab at asset store
    there is runtime and sample folder..
    but what i got only source folder, test folder and documentation
     
    Last edited: Feb 5, 2021
  40. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    178
    I read online documentation, but I cannot find an answer. I understand that this plugin uses Moodle API instead of SCORM API, right? So, what this asset has to do with SCORM?
     
  41. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    Uses the Moodle Rest API and within it the available Scorm endpoints.
     
    pep_dj likes this.
  42. mader_enova

    mader_enova

    Joined:
    Sep 24, 2018
    Posts:
    6
    Hi,
    you said that one must create a course with Scorm type activities in Moodle first. But how can I achieve this? Do I have to create a Scrom Package with the SCORM API first and upload it as a new activity, and then set the scores of the activity with an external Application? (When doing so also getting {"scorms":[],"warnings":[]})
    Or can every activity be marked as SCORM?
     
  43. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    You need to create a dummy Scorm package and upload it as a la course activity because it has to exist in moodle database so you can use the API.
     
  44. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    It seems that bolt comes also with ionic.zip.dll so you need to remove one of those dlls.
     
  45. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    This asset it's NOT supposed to be used INSIDE of a LMS. It's for using OUTSIDE of a LMS.

    This asset it's mainly focused on non web platforms as it'd explained in the asset store page: https://assetstore.unity.com/packag....1616322432-1667845816.1608322372#description

    For that purpose (running inside LMS) there is another asset:

    https://assetstore.unity.com/packages/tools/integration/scorm-api-53523
     
  46. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    I don't understand the problem you are having in that screenshot. The Scorm API asset doesn't come with a custom template on 2.x versions and you are having an error on the Unity build which does not seem to have anything to do with my asset.
     
  47. neatgadgets

    neatgadgets

    Joined:
    May 13, 2014
    Posts:
    73
    I just installed into 2019.4.13f and got a heap of "The type namespace..." errors. Do you know hwat the issue is? This is the Moodle API and the SCORM API.
     
  48. neatgadgets

    neatgadgets

    Joined:
    May 13, 2014
    Posts:
    73
    Ok I just removed the Tests from reading above. The documentation equates to

    1. Add the “Moodle API” component. (How do I "Add" and what exactly is the "Moodle API" that I add?)
    2. Set the “Host” value in the inspector (or by code). Example: “http://localhost”. Where?
    3. Start using the endpoints. (What are the enpoints?)

    Then how do I connect a score to record?
     
  49. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    In the latest version (1.1) there is no Tests folder so that problem should not appear.

    You have a "Sample" scene where you can see a basic login example.

    In ths online docs you can see more examples and the complete API reference.
     
  50. d41602031

    d41602031

    Joined:
    Jan 5, 2015
    Posts:
    7
    Hi,
    We are planning to buy Moodle API but
    I would like to know if we can get all students inside a course, for example. And, if we can get the list of courses...
    According to this reference or something like that: Data manipulation API - MoodleDocs

    Thanks in advance!