AnsweredAssumed Answered

How to POST in powershell

Question asked by Franco Pettigrosso on May 24, 2016
Latest reply on Jun 6, 2016 by Franco Pettigrosso


Hello everyone,

     I am currently making an API for an university. The purpose of this project to to look at every course and check if it contains a certain module and if not, add one in. Seems fairly simple enough, but the thing that is making the project complicated is on learning the syntax on to actually do it! I am writing this code in powershell and I have tried to use curl and invoke web request. I tried following canvas' documentation, but I cannot get it. Here are two instances I have, can you please show me how to properly format this.

 

this is the first way I tried it and the error I get Invoke-WebRequest : {"message":"missing module parameter"}

######

$temp2=($mainURL+$course.ID+"/modules"+$securityToken)

$reply = curl -Uri $temp2  -Method Post -Body '{"module[name]"="Getting started","module[position]"="1"}'

#######

 

This is the second way I've tried and the error I get Invoke-WebRequest : The remote server returned an error: (422) Unprocessable Entity.

#########

$url="https://University.instructure.com/api/v1/courses/1371/modules?access_token=abc123"

$body= "{'module[name]'='Getting started,'module[position]'=1}"

Invoke-WebRequest -Uri $url -ContentType "application/json" -Method Post -Body $body

#########

Outcomes