I'm using the Canvas API to create pages and link these created pages dynamically between other pages. If the page has been created before in the course, regardless of whether the page has been deleted, the page slug (ex: the "week-1" in "https://xxx.instructure.com/courses/799908/pages/week-1") adds a hyphen and number to the end of the slug where the number increments depending on how many times the same page name has been created before.
This behavior is not ideal when trying to "predict" the page slug for automatically generated links. Could someone help navigate this issue? Below is similar to the code I'm using to upload pages.
headers = {"Authorization": f"Bearer {access_token}"}
slug = re.sub(r"[^a-z0-9]+", "-", title.lower()).strip("-")
data = {
"wiki_page[title]": title,
"wiki_page[body]": html_content,
"wiki_page[published]": True,
"on_duplicate": "overwrite",
}
data["wiki_page[page_url]"] = slug
resp = requests.post(
f"https://xxx.instructure.com/api/v1/courses/{course_id}/pages",
headers=headers,
data=data,
resp.raise_for_status()
return resp.json()