Canvas Data API Sync Route and Expiring Download Urls

Jump to solution
lawd
Community Participant

      I am running into an issue when using the "/api/account/self/file/sync" endpoint on the Canvas Data API. Within the returned json, each file has a download url. Within each download url there is an 'expires=<epoch timestamp>" that indicates the time the download url will expire. After looking into these timestamps, it appears that each download url expires 2 hours after you hit the sync endpoint. Two hours is more than enough time to download one file; however, this is not enough time for us to loop through the entire json object to hit and download from each download url. As you can imaging, after 2 hours my application stops hitting legitimate urls.

       The documentation doesn't seem to mention anything about handling the expiring urls. My process is essentially the process the documentation recommends for the file/sync endpoint which is:

- Make a request to this API, for every file:

  - If the filename has been downloaded previously, do not download it

  - If the filename has not yet been downloaded, download it

- After all files have been processed, delete any local file that isn't in the list of files from the API

Is anyone else having this issue? How are others handling the expiring urls?

Labels (1)
0 Likes
1 Solution
lawd
Community Participant
Author

       I have since figured out a solution, and I figured I would post my idea to help any future sages attempting this journey or at least start a conversation on how others might handle this. Essentially I gathered the json from the sync schema and looped through it as I had before. The update I made to avoid the expiring urls was this: for each file I looped through, I would re-hit the sync endpoint, find the file I was currently on within the refreshed schema, and gather it's url. Essentially this refreshes the download url for the file and the date that it expires. I have ran this guy several times and everything is running as smooth as can be.

       I hope this helps any other brave souls interested in going down this path or at least gets a conversation going if any others have different or better ideas.

View solution in original post