2016-05-25 12 views
0

私は現在大学向けのAPIを作成中です。このプロジェクトの目的は、すべてのコースを見て、特定のモジュールが含まれているかどうかをチェックし、そうでない場合は、1つを追加することです。プロジェクトは複雑になっていますが、実際にはそれ!私はこのコードをpowershellに書いています。私はcurlを使い、Webリクエストを呼び出そうとしています。私はキャンバスのドキュメントに従ってみましたが、私はそれを手に入れることはできません。ここに私が持っている2つの例があります。あなたが適切にこれをフォーマットする方法を教えてください。ウェブサイトhttps://canvas.instructure.com/doc/api/index.htmlpowershellでキャンバスにPOSTする方法LMS

UPDATE 2016年5月26日 から

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

ドキュメント私は適切にメッセージの本文をフォーマットする方法を考え出しました。今すぐエラーメッセージが表示されます

$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 

この時点で何をすべきか分かりません。

答えて

0

JSONの実際の形式で1週間練習した後、Invoke-WebRequestのコンテンツタイプを取り出して、サーバーがそのフォーマットを推測できるかどうかを確認しました。出来た!

関連する問題