- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2021
09:01 AM
PowerShell Syntax for SIS Import API Upload File
If you are uploading CSV Imports (or zip files) to the SIS Imports API and are using PowerShell, would you care to share your syntax for setting up the Invoke-WebRequest?
Thanks
Solved! Go to Solution.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2021
09:54 AM
We previously used this one before I switched everything to using Python.
$sourceDir = "C:\path\to\store\csvs\" #this is source directory literal path
$outputPath = "C:\path\to\store\outputzip\" #output path for the zip file creation
$domain = "yourdomain.instructure.com"
$account_id = "1"
$token = "TOKEN_GOES_HERE"
$outputZip = "ZIP FILE NAME.zip" # name of the zip file to create
$url = "https://$domain/api/v1/accounts/"+$account_id+"/sis_imports.json?import_type=instructure_csv&batch_mode=1"
$headers = @{"Authorization"="Bearer "+$token}
$contentType = "application/zip"
$InFile = $outputPath+$outputZip
write-zip -Path $sourceDir"*.csv" -OutputPath $InFile
$t = get-date -format M_d_y_h
$status_log_path = $outputPath+$t+"LOG_FILE_NAME_HERE.log"
$results1 = (Invoke-WebRequest -Headers $headers -InFile $InFile -Method POST -ContentType $contentType -Uri $url)
$results1.Content | Out-File $status_log_path
$results = ($results1.Content | ConvertFrom-Json)
do{
Write-Host $status_line
$status_url = "https://$domain/api/v1/accounts/"+$account_id+"/sis_imports/"+$results.id
$results1 = (Invoke-WebRequest -Headers $headers -Method GET -Uri $status_url)
$results1.Content | Out-File -Append $status_log_path
$results = ($results1.Content | ConvertFrom-Json)
Start-Sleep -s 300
if($results -eq $null){
break
}
}
while($results.progress -lt 100 -and $results.workflow_state -ne "failed_with_messages")
$results1.Content | Out-File -Append $status_log_path
$download = $results.errors_attachment.url
Move-Item -Force $outputPath$outputZip $outputPath$t-$outputZip
Remove-Item $sourceDir*.csv
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2021
09:54 AM
We previously used this one before I switched everything to using Python.
$sourceDir = "C:\path\to\store\csvs\" #this is source directory literal path
$outputPath = "C:\path\to\store\outputzip\" #output path for the zip file creation
$domain = "yourdomain.instructure.com"
$account_id = "1"
$token = "TOKEN_GOES_HERE"
$outputZip = "ZIP FILE NAME.zip" # name of the zip file to create
$url = "https://$domain/api/v1/accounts/"+$account_id+"/sis_imports.json?import_type=instructure_csv&batch_mode=1"
$headers = @{"Authorization"="Bearer "+$token}
$contentType = "application/zip"
$InFile = $outputPath+$outputZip
write-zip -Path $sourceDir"*.csv" -OutputPath $InFile
$t = get-date -format M_d_y_h
$status_log_path = $outputPath+$t+"LOG_FILE_NAME_HERE.log"
$results1 = (Invoke-WebRequest -Headers $headers -InFile $InFile -Method POST -ContentType $contentType -Uri $url)
$results1.Content | Out-File $status_log_path
$results = ($results1.Content | ConvertFrom-Json)
do{
Write-Host $status_line
$status_url = "https://$domain/api/v1/accounts/"+$account_id+"/sis_imports/"+$results.id
$results1 = (Invoke-WebRequest -Headers $headers -Method GET -Uri $status_url)
$results1.Content | Out-File -Append $status_log_path
$results = ($results1.Content | ConvertFrom-Json)
Start-Sleep -s 300
if($results -eq $null){
break
}
}
while($results.progress -lt 100 -and $results.workflow_state -ne "failed_with_messages")
$results1.Content | Out-File -Append $status_log_path
$download = $results.errors_attachment.url
Move-Item -Force $outputPath$outputZip $outputPath$t-$outputZip
Remove-Item $sourceDir*.csv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2021
11:31 AM
This is brilliant, @MattHanes! Thanks so much!
