0

I have a requirement where i have to create a bulk content item under already selected module in Canvas LMS.

How can I achieve it using Canvas API? I am able o create normal bulk content items under a module by using Create a module item

But in the similar way I want to add LTI content under the module as a module item.

selected_item_ids = [1,2,3,4]
course_id = params[:course_id]
module_id = params[:module_id]
form_data["modules"]["item"].each do |item|
  if selected_item_ids.include?(item["id"].to_i)
    title = item["title"].to_s
    item_type =  item["type"].to_s
    external_url =  item["external_url"].to_s
    secret =  item["secret"].to_s

    uri = URI.parse("http://example/api/v1/courses/"+course_id+"/modules/"+module_id+"/items")
    request = Net::HTTP::Post.new(uri)
    request["Authorization"] = "Bearer <token>"
    request.body = "module_item[title]="+title+"&module_item[type]=ExternalUrl&module_item[new_tab]=true&module_item[external_url]="+external_url

    req_options = {
      use_ssl: uri.scheme == "https",
    }

    response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
      http.request(request)
    end
  end
end

Thanks in advance.

1 Answers1

0

Based on their documentation and some tries by myself. It seems to zip file and upload one file might be the only way for the bulk files.

Brandon
  • 60
  • 5