This PowerShell script will pull user info from a CSV file and create a Canvas Conversation for each, with the unique Survey URL for each. **I'm not a programmer, and there is no guarantee with this script, but if it helps, please use it.
---
$token = "3474~MA07brX7mM7PzhkgIW0m8sp0H0XjHW5CUFJwoiNrRxnrOkWN0ONXDUEjAucDmYza"
$canvas_domain = "myschool.test.instructure.com" # Your Canvas domain. Use the .test area at first
$headers = @{"Authorization"="Bearer "+$token}
Import-Csv C:\canvas_conversations\source_file.csv | ForEach-Object {
$user_id = $_.user_id
$first_name = $_.first_name
$survey_url = $_."survey_url"
$uri = "https://"+$canvas_domain+"/api/v1/conversations/?recipients[]=$user_id&subject=NSSE Survey&body=+$first_name, `r`nPlease take the NSSE Survey. `r`nEach survey is especially designed for you. `r`n+$survey_url"
Write-Host $uri
Invoke-RestMethod -Method POST -uri $uri -Headers $headers
}
---
The source_file.csv would have three columns: user_id, first_name, survey_url
*I have not seen the actual source_file provided by NSSE, but might have to translate the STUDENTID to the Canvas UserID which is used in the API call. I generated the "Provisioning Report" from the Canvas Admin Menu to give me the Canvas UserID. **Also remember that the access token needs to be generated by a user with enough permissions to create the Conversations. I created a "NSSE" user and assigned them to the Account Admin role.
This is what the Canvas Conversation looks like for one student (with dummy Survey URL):
NOTES: A further caveat...
What if you want to recall these generated Conversations? The Conversations API does have a "delete" option, but you have to know the Conversation "ID". I have not found an easy way to create a list of these Conversation IDs. I thought pushing display output to a logfile would be nice, but it does not appear to be straightforward for PowerShell. *So, if someone could find a way to generate a list of Conversation IDs to be used to remove them, if desired, that would be great!
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.