繁体   English   中英

如何在Powershell中发布以画布LMS

[英]How to POST in powershell to canvas LMS

我目前正在为大学制作API。 这个项目的目的是查看每门课程,并检查它是否包含某个模块,如果不包含,则添加一个。看起来相当简单,但是使项目变得复杂的是学习语法的实际作用。它! 我在Powershell中编写此代码,并且尝试使用curl和调用Web请求。 我尝试按照画布的文档进行操作,但无法获取。 这是我的两个实例,请您告诉我如何正确格式化。

######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
#########

网站上的文档https://canvas.instructure.com/doc/api/index.html

更新5-26-2016我已经弄清楚了如何正确设置邮件正文的格式。 现在我收到错误消息

$header = @{"Authorization"="Bearer "+ $security_token}
$body=  '{"module[name]":"Getting started","module[position]":"1"}'
$curlly=Invoke-WebRequest -Headers $header -Body $body -Method Post -ContentType "application/json"  -Uri ($url_main+"courses/1371/modules")   
$module = ConvertFrom-Json $curlly.Content    
curl : Invalid URI: The hostname could not be parsed.
    At line:1 char:1
    + curl
    + ~~~~
        + CategoryInfo          : NotSpecified: (:) [Invoke-WebRequest], UriFormatException
        + FullyQualifiedErrorId : System.UriFormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

我真的不知道该怎么办,在这一点上任何指导将不胜感激。

在经过一周的实际JSON格式摆弄之后,我在Invoke-WebRequest上取出了内容类型,以查看服务器是否能够猜测该格式。 有效!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM