The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December.
Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
I'm working on a google sheet that will allow me to manage announcement publish dates in bulk. It should work similarly to @James extension Adjust All Assignment Dates on One Page as well as the spin-off version bulk editor I created a few weeks ago: Canvas Bulk Date Editor (Google Sheet). I'm simply altering the work to be able to adjust announcement dates.
I have managed to GET the announcements via the discussion API using only_announcements=1 as the parameter. I can alter the dates and prepare the return API call to send the new dates back to Canvas, but I can't figure out why they do not get updated in Canvas.
I'm sure it's related to the API, so maybe someone here can point me in the right direction.
Starting with James' original sheet, the payload (parms) looks like this:
{assignment[due_at]=2018-01-09T02:00:00Z}
{quiz[due_at]=2018-01-10T13:00:00Z}
My payloads look like this:
{discussion[delayed_post_at]=2018-01-15T13:00:00Z}
{discussion[delayed_post_at]=2018-01-12T13:00:00Z}
The url looks like this:
https://scf.instructure.com/api/v1/courses/20565/discussion_topics/148628
The next script line is this:
var response = UrlFetchApp.fetch(url, parms);
Which seems to return the original announcement without any changes.
I'm using the original canvasAPI.gs that James created and it works for quizzes and assignments. From the way I understand URLFetchApp works, it should POST the parameters to the URL in Canvas, right?
Is there any way to debug what's happening when Canvas receives the https request?
You are welcome to look at the google doc here:
I don't have time to look into this right now as I'm backlogged in my own work, so I'll just throw some things out there.
The UrlFetchApp will support POST, as long as you put in a method and payload property. It also supports PUT and Canvas normally uses a PUT when you're updating something and POST when you're creating something. You would need something like (myPayload is whatever you called your parameter structure)
{
"method" : "put",
"payload" : myPayload
}However, if you're using my script, it facilitates that by allowing you to just copy/paste the information from the Canvas REST API. Here's an example from mine. The item is an object that contains course_id and id properties. Anything else is sent through as a parameter. You would need a object called "discussion" that had the parameters.
result = canvasAPI('PUT /api/v1/courses/:course_id/assignments/:id', item);When editing a script, you can go to the View and choose Execution Script. That probably won't show you all of the parameters that were sent, but it will let you know that the call is getting made. It shows up something like this (I've split the one item onto multiple lines to help with readability.
[17-11-12 17:32:57:496 PST] PropertiesService.getUserProperties() [0 seconds]
[17-11-12 17:32:57:501 PST] Properties.getProperties() [0.004 seconds]
[17-11-12 17:32:58:241 PST] UrlFetchApp.fetch(
[https://richland.instructure.com/api/v1/courses/2206220/assignments/15624983,
{headers={Authorization=Bearer <removed>}, method=put, payload={assignment[due_at=}}]...)
[0.738 seconds]
[17-11-12 17:32:58:241 PST] HTTPResponse.getResponseCode() [0 seconds]
[17-11-12 17:32:58:241 PST] HTTPResponse.getAllHeaders() [0 seconds]
[17-11-12 17:32:58:241 PST] HTTPResponse.getContentText() [0 seconds]
[17-11-12 17:32:58:299 PST] Execution succeeded [6.217 seconds total runtime]
There is a debug mode in the script editor. You can set a breakpoint and run it to a certain spot and look at the information that it has gathered. You can also use Logger.log() statements and then go into the View > Logs after running it to look at the output. The objects don't come out as nicely as in debug mode, but you can copy/paste it into a JSON formatter and clean it up if needed.
Finally, make sure that what you think you're trying to send actually works outside of Google Scripts. You can use the Live API (tack /doc/api/live onto the end of your Canvas Instance base URL) or a REST client like Postman or Advanced Rest Client (ARC).
Thanks, James. I appreciate that you are busy so this can wait until whenever. . . Many times when working on something like this, I get stuck where someone else might look at it for 30 seconds and see the answer.
It looks to me like the http request is correct, but for some reason it doesn't work for announcements (discussion_topics). I was just hoping it would work out of the box since I'm just reusing your code, but I'm worried it might be something weird about the API for announcements. After all, I'm using the discussion_topics API to get them, so many I can't send them back this way?
[17-11-12 20:12:41:668 PST] PropertiesService.getUserProperties() [0 seconds]
[17-11-12 20:12:41:673 PST] Properties.getProperties() [0.004 seconds]
[17-11-12 20:12:42:045 PST] UrlFetchApp.fetch([https://scf.instructure.com/api/v1/courses/20565/discussion_topics/148633, {headers={Authorization=Bearer <removed>}, method=put, payload={discussion[dela=}}]...) [0.371 seconds]
[17-11-12 20:12:42:046 PST] HTTPResponse.getResponseCode() [0 seconds]
[17-11-12 20:12:42:046 PST] HTTPResponse.getAllHeaders() [0 seconds]
[17-11-12 20:12:42:046 PST] HTTPResponse.getContentText() [0 seconds]
[17-11-12 20:12:42:473 PST] Execution succeeded [4.394 seconds total runtime]
I still haven't had time to test this, but are you using the Update a topic endpoint? If so, the documentation doesn't show it wrapped inside a discussion object. Instead of discussion[delayed_post_at]=, try just delayed_post_at=
@James This is a super old post but I wanted to know if there is a central resource for projects people have shared that have utilized the use of Google Apps Script to do Canvas API calls. I have some experience on doing so, and have some running templates but there are a few things I am not sure on and do not want to reinvent the wheel. I am currently using:
myinstitution.instructure.com/doc/api/live#
Class UrlFetchApp | Apps Script | Google Developers (and all other pages)
There isn't a central resource that I've found, yet. A couple of people have toyed with the idea of creating some central list, but it hasn't happened, yet. I keep on tacking on "yet" as a growth mindset.
I've got my pages, which are linked from the Canvancements - Canvas Enhancements page and some other people have mentioned taking that and adding their own code on the pages. For example, I think a couple of people have modified the adjust all due dates code.
I'll have to check that out. I'm trying to do a POST with a payload and it's just not working. I tried examining your code from the due dates script to see how that is working but it's not clicking for me.
James, thank you--that was it. How can you read that API page and know it's not wrapped in an object? Maybe I need to read the other APIs to see the difference. The APIcalls they use as examples are all curl. If I could see just one http call with the parameters I would be able to see the difference!
Anyway, thank you. I don't have time to finish this project today, but as soon as I can I'll post it on here.
Thanks again!
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in