Find a course across all subaccounts

Jump to solution
binodpanta
Community Member

We are currently using the conclude option when we remove courses from our catalog now, and I am attempting to make a 'create_or_update' pattern so if we ever try to re-add a course to a catalog again, and transmit, we can change the course back from 'concluded' to 'offer' state (using the "course[event]" option here). Currently we simply fail the create operation, because we don't check if the course exists even if in deleted / concluded state... 😞

 
I am having trouble finding an api endpoint that can search for a course across all subaccounts regardless of the state it is in. Looks like I can only find under one account at a time. This means I have to loop over all subaccounts using this recursive option 
{{canvas_url}}/api/v1/accounts/1/sub_accounts?per_page=100&recursive=true
 
then loop over all subaccounts and accounts to find the course  using https://canvas.instructure.com/doc/api/accounts.html#method.accounts.courses_api
 
😞 hopefully there is an easier way? 
 
The reason I need to find under all subaccounts is that the course could have been added under a different subaccount or moved to a different subaccount and I would still need to be able to find it before I can decide if I need to create it or just update it.
 
 
Labels (1)
0 Likes
1 Solution
binodpanta
Community Member
Author

Thanks for your reply! 

 

I ended up looking up a root account using api, I can detect it because it has parent_account_id:null

then when I point my api to search courses for that account id instead, now I can find courses even under other subaccounts! 

this solves the problem for me

 

View solution in original post