我有以下代碼來獲取數據drom Canvas REST API這個數據包含的信息比如coursse的開始日期和結束日期。我必須更改這個end_date當然。我使用GET來獲取信息,如圖計劃:如何在Canvas中使用curl使用PUT指令rest api
#!/usr/bin/perl
use strict;
use JSON::Parse 'parse_json';
my $auth = "xxx";
my $curl = "curl -H 'Authorization: Bearer $auth'";
#system("curl -H 'Authorization: Bearer $auth'https://canvas.instructure.com/api/v1/courses");
#system("curl -H 'Authorization: Bearer $auth' https://canvas.instructure.com/api/v1/accounts/$accountid/analytics/current/grades");
system("$curl https://canvas.instructure.com/api/v1/courses/10300000000000133");
my $json = '["golden", "fleece"]';
my $perl = parse_json ($json);
程序的輸出是:
{"id":10300000000000133,"name":"DOV DEV","account_id":10300000000000001,"start_at":"2014-07-01T13:31:00Z","grading_standard_id":null,"is_public":true,"course_code":"DOV DEV","default_view":"feed","enrollment_term_id":10300000000000001,"end_at":"2016-05-28T04:00:00Z","public_syllabus":false,"storage_quota_mb":15000,"is_public_to_auth_users":false,"hide_final_grades":false,"apply_assignment_group_weights":false,"calendar":{"ics":"https://canvas.instructure.com/feeds/calendars/course_Jo1suCoQU3XhYMBJNm3Ziu2POTG4GL6DjzHJ7PM4.ics"},"sis_course_id":null,"integration_id":null,"enrollments":[{"type":"teacher","role":"TeacherEnrollment","role_id":822,"user_id":10300000000020171,"enrollment_state":"active"}],"workflow_state":"available","restrict_enrollments_to_course_dates":false}host-155-246-165-53:~ ajinkyabobade$
獲取信息如上圖所示,我使用-X PUT命令後改變end_date。包括PUT的代碼如下
#!/usr/bin/perl
use strict;
use JSON::Parse 'parse_json';
my $auth = "xxx";
#my $accountid = "10300000000000133";
my $curl = "curl -H 'Authorization: Bearer $auth'";
#system("curl -H 'Authorization: Bearer $auth' https://canvas.instructure.com/api/v1/courses");
#system("curl -H 'Authorization: Bearer $auth' https://canvas.instructure.com/api/v1/accounts/$accountid/analytics/current/grades");
system("$curl https://canvas.instructure.com/api/v1/courses/10300000000000133 -X PUT -d 'end_at=2017-05-28T04:00:00Z' ");
my $json = '["golden", "fleece"]';
my $perl = parse_json ($json);
的END_DATE使用此代碼還我得到下面的輸出沒有變化,請幫助
{"id":10300000000000133,"name":"DOV DEV","account_id":10300000000000001,"start_at":"2014-07-01T13:31:00Z","grading_standard_id":null,"is_public":true,"course_code":"DOV DEV","default_view":"feed","enrollment_term_id":10300000000000001,"end_at":"2016-05-28T04:00:00Z","public_syllabus":false,"storage_quota_mb":15000,"is_public_to_auth_users":false,"hide_final_grades":false,"apply_assignment_group_weights":false,"calendar":{"ics":"https://canvas.instructure.com/feeds/calendars/course_Jo1suCoQU3XhYMBJNm3Ziu2POTG4GL6DjzHJ7PM4.ics"},"sis_course_id":null,"integration_id":null,"workflow_state":"available","restrict_enrollments_to_course_dates":false}host-155-246-165-53:~ ajinkyabobade$
如果退出捲曲,最好使用'LWP'。由於正確的代碼取決於instructure.com API – Borodin