invoke-restmethod multipart content

%3CLINGO-SUB%20id%3D%22lingo-sub-1718918%22%20slang%3D%22en-US%22%3Einvoke-restmethod%20multipart%20content%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1718918%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20PowerShell%20script%20that%20calls%20the%20Canvas%20VLE%20SIS%20import%20API%20to%20batch%20enrol%20students%20into%20a%20course.%26nbsp%3B%20The%20script%20calls%20invoke-restmethod%20to%20post%20a%20multipart%20CSV%20file%20with%20the%20details%20of%20the%20students%20to%20enrol.%26nbsp%3B%20This%20is%20the%20format%20of%20the%20file%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E--CanvasData%0AContent-Disposition%3A%20form-data%3B%20name%3D%22attachment%22%3B%20filename%3D%22enrol_S2020-A52172-D0016-1.csv%22%0AContent-Type%3A%20text%2Fcsv%3B%20charset%3Dutf-8%0A%0A%22section_id%22%2C%22user_id%22%2C%22role%22%2C%22status%22%0A%22S2020-A52172-D0016%22%2C%22000000%22%2C%22student%22%2C%22active%22%0A%22S2020-A52172-D0016%22%2C%22111111%22%2C%22student%22%2C%22active%22%0A%22S2020-A52172-D0016%22%2C%22222222%22%2C%22student%22%2C%22active%22%0A%22S2020-A52172-D0016%22%2C%22333333%22%2C%22student%22%2C%22active%22%0A%22S2020-A52172-D0016%22%2C%22444444%22%2C%22student%22%2C%22active%22%0A--CanvasData--%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20content%20is%20uploaded%20and%20processed%20successfully%20when%20running%20on%20PowerShell%204.0.%26nbsp%3B%20However%2C%20if%20I%20run%20the%20same%20script%20in%20PowerShell%205.1%2C%20the%20content%20is%20uploaded%20but%20the%20processing%20fails.%26nbsp%3B%20I%20have%20verified%20that%20the%20CSV%20content%20is%20valid%2C%20so%20the%20only%20reason%20for%20this%20failure%20that%20I%20can%20think%20of%20is%20that%20PowerShell%205.1%20handles%20multipart%20content%20different%20to%204.0.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20suggestions%20on%20how%20I%20can%20change%20the%20script%20%2F%20multipart%20content%20so%20that%20the%20enrolment%20upload%20works%20on%20PowerShell%205.1%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1718918%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Einvoke-restmethod%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Occasional Visitor

I have a PowerShell script that calls the Canvas VLE SIS import API to batch enrol students into a course.  The script calls invoke-restmethod to post a multipart CSV file with the details of the students to enrol.  This is the format of the file:

 

 

 

 

--CanvasData
Content-Disposition: form-data; name="attachment"; filename="enrol_S2020-A52172-D0016-1.csv"
Content-Type: text/csv; charset=utf-8

"section_id","user_id","role","status"
"S2020-A52172-D0016","000000","student","active"
"S2020-A52172-D0016","111111","student","active"
"S2020-A52172-D0016","222222","student","active"
"S2020-A52172-D0016","333333","student","active"
"S2020-A52172-D0016","444444","student","active"
--CanvasData--

 

 

 

 

The content is uploaded and processed successfully when running on PowerShell 4.0.  However, if I run the same script in PowerShell 5.1, the content is uploaded but the processing fails.  I have verified that the CSV content is valid, so the only reason for this failure that I can think of is that PowerShell 5.1 handles multipart content different to 4.0.

 

Any suggestions on how I can change the script / multipart content so that the enrolment upload works on PowerShell 5.1 ?

0 Replies