-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_course_data.ps1
More file actions
40 lines (35 loc) · 1.57 KB
/
pull_course_data.ps1
File metadata and controls
40 lines (35 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
$LMSURL = "https://your.learn.tld"
$key = "yourappkey"
$secret = "yourappsecret"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $key,$secret)))
$body = "grant_type=client_credentials"
$apiuri = "$LMSURL/learn/api/public/v1/oauth2/token"
try {
$response = Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -body $body -Uri $apiuri -Method Post
}
catch {
write-host "Error calling API at $apiuri`n$_"
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
}
$token = $response.access_token
#$apiuri = "$LMSURL/learn/api/public/v1/courses/_PRIMARYFORCOURSE_1"
#$apiuri = "$LMSURL/learn/api/public/v1/courses/courseId:COURSEIDFORCOURSE"
#$apiuri = "$LMSURL/learn/api/public/v1/courses/externalId:BATCHUIDFORCOURSE"
# 5 courses that are visible and created after 1/1/2018
#$apiuri = "$LMSURL/learn/api/public/v1/courses?created=2018-01-01&limit=5&availability.available=Yes"
$apiuri = "$LMSURL/learn/api/public/v1/courses"
$apimethod = "GET"
try {
$response = Invoke-RestMethod -Headers @{Authorization=("Bearer $token")} -Uri $apiuri -Method $apimethod
} catch {
write-host "Error calling API at $apiuri`n$_"
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
}
if($response.results -is [array]) {
foreach($r in $response.results) { $r }
"Returned {0} courses`n" -f $response.results.count
} else {
$response
}