Creating Topics and Modules via API - working examples?

Matt.J.517
Matt.J.517 Posts: 5 🌱
edited November 4 in Social Groups
Hi all, I'm looking for examples of creating modules and topic via the API. I'm learning using postman to ensure each request has the correctly formatting JSON and reading the documents. I regularly get 400 errors due to my JSON being incorrect. Debugging this requires a lot of removing & editing lines and it can be very time intensive.

If anyone has a collection of know, working, examples across the activity types it would be much appreciated.

The more the better IMO!! Thanks in advance.
Tagged:

Comments

  • Justin.B.253
    Justin.B.253 Posts: 35 🌱

    I tried multiple times and can not figure this out as well. I get the same error message as you do.

  • Justin.B.253
    Justin.B.253 Posts: 35 🌱

    @Matt.J.517 I got it to work - I just needed the help of ChatGPT to read all the documentation and it was finally able to create the correct JSON code for the Body in Postman.

    {
    "Title": "Simple Module",
    "ShortTitle": "Module", // Optional, can be empty or null
    "Type": 0,
    "ModuleStartDate": null, // Optional, can be set to a UTC DateTime string if needed
    "ModuleEndDate": null, // Optional, can be set to a UTC DateTime string if needed
    "ModuleDueDate": null, // Optional, requires LE API v1.70 or higher if setting a due date
    "IsHidden": false, // Optional, set true if you want the module hidden by default
    "IsLocked": false, // Optional, set true if you want the module locked
    "Description": {
    "Text": "Module description text",
    "Html": "<p>Module description text</p>"
    },
    "Duration": null // Optional, set to an integer for minutes if using unstable contract
    }

    Explanation of Fields:

    • Title: Required; a non-empty string for the module’s title.
    • ShortTitle: Optional; can be an empty string or null.
    • Type: Required; must be 0 for modules.
    • ModuleStartDate, ModuleEndDate, ModuleDueDate: Optional; if provided, these should be in UTC DateTime format (e.g., "2024-10-20T00:00:00Z").
    • IsHidden, IsLocked: Optional; true or false values to control visibility and locking.
    • Description: Optional; uses the RichTextInput structure with Text and Html fields.
    • Duration: Optional; if your environment uses LE's unstable contract, specify minutes required to cover the module.

    Important Notes:

    1. UTC Date Format: If you need to set ModuleStartDate, ModuleEndDate, or ModuleDueDate, use a valid UTC format, e.g., "2024-10-20T00:00:00Z".
    2. Description Format: The Description field should use both Text and Html keys for text and HTML content.
    3. Token Permissions: Ensure the API token has the content:modules:manage scope.

  • Matt.J.517
    Matt.J.517 Posts: 5 🌱

    thanks @Justin.B.253 how did you get on with Topics? Modules are a good start but then you move into topics and then you'll see how much more is required to get going! Adding a weblink is ok - adding a Forum is a beast.

  • Justin.B.253
    Justin.B.253 Posts: 35 🌱

    @Matt.J.517 It took a bit of time only because I was trying to send data to the wrong course, but I was able to get the topic with a link to work. I haven't been successful with creating a file (HTML page) or linking to a file like a .pdf document.

    With a link -
    { "Title": "Sample Topic", "ShortTitle": "Sample", "Type": 1, "TopicType": 3, "Url": "https://example.com", "StartDate": null, "EndDate": null, "DueDate": null, "IsHidden": false, "IsLocked": false, "OpenAsExternalResource": true, "Description": { "Text": "This is a sample topic description", "Html": "<p>This is a sample topic description</p>" }, "MajorUpdate": true, "MajorUpdateText": "Sample Topic Updated", "ResetCompletionTracking": true, "Duration": 30}

    I'll play with Discussion Boards as well.