Update course start and end time time through API

Jump to solution
Community Explorer

I am trying to write a program for my team to update course start and end times through the API using Python. The end_at time isn't updating. What am I doing wrong? I've code below for obvious reasons. 


import requests

secret_token = "MY_SECRET_TOKEN"

headers = {'Authorization' : 'Bearer ' + secret_token}
pagesURL = 'MY_INSTITUTION/api/v1/courses/COURSE_ID'
r = requests.get(pagesURL,headers = headers)
i = r.json()
start = i["start_at"]
time = '2024-10-05T17:19:17Z'
end = {"course[end_at]":time}
data = requests.post(pagesURL,headers = headers, params = end)


Labels (2)
1 Solution
Community Coach
Community Coach

Hi @bertscjn1,

A couple things jump out at me right away...

First, you're doing a post call, when to modify an existing course you want to use a put call.

Second, I'm confused by your print statements at the end.  You're not changing the start time, so that doesn't matter too much.  But when printing the end time, you're printing from i, which is going to have the original end time of the course, not your updated one.  Unsure if that's intentional or not.

Adjusting those may help!


View solution in original post