簡體   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