AnsweredAssumed Answered

Code Issue with Sub - Account Terms

Question asked by Jason Marshall on Jan 10, 2018
Latest reply on Jan 23, 2018 by Jason Marshall

I'm having a little trouble running some 3rd party grade pull code on our system and getting this error:

 

C:/Ruby23-x64/lib/ruby/gems/2.3.0/bundler/gems/canvas-api-2e114163f7af/lib/canvas-api.rb:119:in `retrieve_response': Terms only belong to root_accounts. (Canvas::ApiError)

 

From what I can tell (I'm not terribly experienced with this sort of thing), it seems to be having an issue with a Sub - Account that we created for our Athletics department. We have all of those courses assigned to their own year - round term. My workaround was to remove the Sub - Account entirely, but that is not optimal, as we would like to use Sub - Accounts in Canvas.

 

Here is the relevant piece of code:

 

def get_current_enrollment_term_ids(account_id)
enrollment_terms = @canvas.get("/api/v1/accounts/#{@account_id}/terms")['enrollment_terms']
sorted_terms = enrollment_terms.select{|term| term['start_at'] != nil && (Date.today - Date.parse(term['start_at'])) > 30 }.sort_by!{|term| Date.parse(term['start_at'])}
current_term_id = sorted_terms.select{|term| !term['name'].include?('Full Year')}.last['id']
current_year_term_id = sorted_terms.select{|term| term['name'].include?('Full Year')}.last['id']
[current_year_term_id, current_term_id]
end

 

I'm thinking perhaps we can't assign Terms to Sub - Accounts? Does anyone do anything like this? Any help or insight would be greatly appreciated.

Outcomes