Skip to content

Instantly share code, notes, and snippets.

@chomamateusz
Created July 26, 2021 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chomamateusz/7a4a75e79db1506057907c42d33950ad to your computer and use it in GitHub Desktop.
Save chomamateusz/7a4a75e79db1506057907c42d33950ad to your computer and use it in GitHub Desktop.
copy-contents-to-chapter
(async ({ sourceCourseId, targetChapterId }) => {
const getContents = async (id) => {
const response = await fetch("https://coderoad.thinkific.com/api/v2/courses/" + id, {
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
})
const data = await response.json()
return data.contents
}
const copy = (ids, toChapter) => {
const formData = new FormData()
ids.forEach((id) => {
formData.append('content_ids[]', id)
})
formData.append('to_chapter_id', toChapter)
formData.append('accepts', 'application/json')
return fetch("https://coderoad.thinkific.com/api/v2/contents/copy", {
"body": formData,
"method": "POST",
"mode": "cors",
"credentials": "include"
})
}
const contents = await getContents(sourceCourseId)
const contentIds = contents.map(({ id }) => id)
return copy(contentIds, targetChapterId)
})({ sourceCourseId: 1465058, targetChapterId: 6503487 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment