【问题标题】:How to POST in powershell to canvas LMS如何在 powershell 中发布到画布 LMS
【发布时间】:2016-06-06 22:31:28
【问题描述】:

我目前正在为一所大学制作 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的文档

2016 年 5 月 26 日更新 我已经弄清楚如何正确格式化消息的正文。现在我收到错误消息

$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 powershell webrequest canvas-lms


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      • 2021-09-07
      • 1970-01-01
      • 2019-07-09
      • 2015-06-20
      相关资源
      最近更新 更多