Created
July 26, 2021 14:24
-
-
Save chomamateusz/7a4a75e79db1506057907c42d33950ad to your computer and use it in GitHub Desktop.
copy-contents-to-chapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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