Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

Create Task

See more Microsoft Tasks and Plans Examples

Demonstrates how to create a new plannerTask.

See https://docs.microsoft.com/en-us/graph/api/planner-post-tasks?view=graph-rest-1.0 for more information.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

// The Microsoft Planner REST API requires an OAuth2 token with the Group.ReadWrite.All scope.
// Use your previously obtained access token as shown here:
//    Get Microsoft Graph OAuth2 Access Token with Group.ReadWrite.All scope.

let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/msGraphGroup.json").is_err() {
    println!("{}", json_token.last_error_text());
    return;
}

http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());

// Create a JSON body for the HTTP POST
// Use this online tool to generate the code from sample JSON: 
// Generate Code to Create JSON

// {
//   "planId": "xqQg5FS2LkCp935s-FIFm2QAFkHM",
//   "bucketId": "hsOf2dhOJkqyYYZEtdzDe2QAIUCR",
//   "title": "Update client list",
//   "assignments": {
//     "fbab97d0-4932-4511-b675-204639209557": {
//       "@odata.type": "#microsoft.graph.plannerAssignment",
//       "orderHint": " !"
//     }
//   },
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("planId", "xqQg5FS2LkCp935s-FIFm2QAFkHM");
let _ = json.update_string("bucketId", "hsOf2dhOJkqyYYZEtdzDe2QAIUCR");
let _ = json.update_string("title", "Update client list");
let _ = json.update_string("assignments.fbab97d0-4932-4511-b675-204639209557.\"@odata.type\"", "#microsoft.graph.plannerAssignment");
let _ = json.update_string("assignments.fbab97d0-4932-4511-b675-204639209557.orderHint", " !");

// POST the JSON to https://graph.microsoft.com/v1.0/planner/tasks

let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://graph.microsoft.com/v1.0/planner/tasks", &json, "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let _ = json.load(&resp.body_str());
json.set_emit_compact(false);

if resp.status_code() != 200 {
    println!("{}", json.emit().unwrap_or_default());
    println!("Failed, response status code = {}", resp.status_code());
    return;
}

println!("{}", json.emit().unwrap_or_default());

// A sample response:
// (See code for parsing this response below..)

// {
//   "createdBy": {
//     "user": {
//       "id": "6463a5ce-2119-4198-9f2a-628761df4a62"
//     }
//   },
//   "planId": "xqQg5FS2LkCp935s-FIFm2QAFkHM",
//   "bucketId": "hsOf2dhOJkqyYYZEtdzDe2QAIUCR",
//   "title": "Update client list",
//   "orderHint": "85752723360752+",
//   "createdDateTime": "2015-03-25T18:36:49.2407981Z",
//   "assignments": {
//     "fbab97d0-4932-4511-b675-204639209557": {
//       "@odata.type": "#microsoft.graph.plannerAssignment",
//       "assignedBy": {
//         "user": {
//           "id": "6463a5ce-2119-4198-9f2a-628761df4a62"
//         }
//       },
//       "assignedDateTime": "2015-03-25T18:36:49.2407981Z",
//       "orderHint": "RWk1"
//     }
//   },
//   "id":"01gzSlKkIUSUl6DF_EilrmQAKDhh"
// }

// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

let created_by_user_id = json.string_of("createdBy.user.id").unwrap_or_default();
let plan_id = json.string_of("planId").unwrap_or_default();
let bucket_id = json.string_of("bucketId").unwrap_or_default();
let title = json.string_of("title").unwrap_or_default();
let order_hint = json.string_of("orderHint").unwrap_or_default();
let created_date_time = json.string_of("createdDateTime").unwrap_or_default();
let assignments_odata_type = json.string_of("assignments.fbab97d0-4932-4511-b675-204639209557.\"@odata.type\"").unwrap_or_default();
let assignments_assigned_by_user_id = json.string_of("assignments.fbab97d0-4932-4511-b675-204639209557.assignedBy.user.id").unwrap_or_default();
let assignments_assigned_date_time = json.string_of("assignments.fbab97d0-4932-4511-b675-204639209557.assignedDateTime").unwrap_or_default();
let assignments_order_hint = json.string_of("assignments.fbab97d0-4932-4511-b675-204639209557.orderHint").unwrap_or_default();
let id = json.string_of("id").unwrap_or_default();

println!("Success.");