Sample code for 30+ languages & platforms
Rust

IntakeQ: Send a Questionnaire

See more IntakeQ Examples

Send an intake package using the API.

Chilkat Rust Downloads

Rust

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

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

// Implements the following CURL command:

// curl -H "Content-Type: application/json" \
//      -H 'X-Auth-Key: xxxxxxxxxxxxxxxxxxxxxxxxx' \
//      -X POST \
//      -d '{     		
// 	"QuestionnaireId": "00000000-0000-0000-0000-000000000000",     		
// 	"ClientId": 123, 
// 	"ClientName": "Dexter Morgan",
// 	"ClientEmail": "dexter@email.com",
// 	"ClientPhone": "2222222222", 
// 	"PractitionerId": "00000000-0000-0000-0000-000000000000",
// }' https://intakeq.com/api/v1/intakes/send

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

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

// The following JSON is sent in the request body.

// {
//   "QuestionnaireId": "00000000-0000-0000-0000-000000000000",
//   "ClientId": 123,
//   "ClientName": "Dexter Morgan",
//   "ClientEmail": "dexter@email.com",
//   "ClientPhone": "2222222222",
//   "PractitionerId": "00000000-0000-0000-0000-000000000000"
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("QuestionnaireId", "00000000-0000-0000-0000-000000000000");
let _ = json.update_int("ClientId", 123);
let _ = json.update_string("ClientName", "Dexter Morgan");
let _ = json.update_string("ClientEmail", "dexter@email.com");
let _ = json.update_string("ClientPhone", "2222222222");
let _ = json.update_string("PractitionerId", "00000000-0000-0000-0000-000000000000");

http.set_request_header("Content-Type", "application/json");
http.set_request_header("X-Auth-Key", "xxxxxxxxxxxxxxxxxxxxxxxxx");

let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://intakeq.com/api/v1/intakes/send", &json, "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);

println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());

let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
    println!("Response Header:");
    println!("{}", resp.header());
    println!("Failed.");
    return;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "Id": "00000000-0000-0000-0000-000000000000",
//   "ClientName": "test",
//   "ClientEmail": "test@email.com",
//   "ClientId": 9999,
//   "Status": "Completed",
//   "DateCreated": 1458526480368,
//   "DateSubmitted": 1458526532654,
//   "QuestionnaireName": "test",
//   "Practitioner": "test@email.com",
//   "PractitionerName": "FirstName LastName",
//   "Questions": [
//     {
//       "Id": "xxxx-1",
//       "Text": "Full name",
//       "Answer": "Dexter Morgan",
//       "QuestionType": "OpenQuestion",
//       "Rows": [
//       ],
//       "ColumnNames": [
//       ],
//       "OfficeUse": false,
//       "OfficeNote": "aaa"
//     },
//     {
//       "Id": "xxxx-2",
//       "Text": "Full name",
//       "Answer": "Dexter Morgan",
//       "QuestionType": "OpenQuestion",
//       "Rows": [
//       ],
//       "ColumnNames": [
//       ],
//       "OfficeUse": false,
//       "OfficeNote": "aaa"
//     }
//   ],
//   "AppointmentId": "xxxxxxxx",
//   "ConsentForms": [
//     {
//       "Id": "00000000-0000-0000-0000-000000000000",
//       "Name": "HIPAA Release Form",
//       "DocumentType": "Html",
//       "Signed": true,
//       "DateSubmitted": 1458526532654
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

let mut j: i32 = 0;
let mut count_j: i32 = 0;

let mut id = j_resp.string_of("Id").unwrap_or_default();
let client_name = j_resp.string_of("ClientName").unwrap_or_default();
let client_email = j_resp.string_of("ClientEmail").unwrap_or_default();
let client_id = j_resp.int_of("ClientId");
let status = j_resp.string_of("Status").unwrap_or_default();
let date_created = j_resp.int_of("DateCreated");
let mut date_submitted = j_resp.int_of("DateSubmitted");
let questionnaire_name = j_resp.string_of("QuestionnaireName").unwrap_or_default();
let practitioner = j_resp.string_of("Practitioner").unwrap_or_default();
let practitioner_name = j_resp.string_of("PractitionerName").unwrap_or_default();
let appointment_id = j_resp.string_of("AppointmentId").unwrap_or_default();
let mut i = 0;
let mut count_i = j_resp.size_of_array("Questions");
while i < count_i {
    j_resp.set_i(i);
    id = j_resp.string_of("Questions[i].Id").unwrap_or_default();
    let _ = j_resp.string_of("Questions[i].Text").unwrap_or_default();
    let _ = j_resp.string_of("Questions[i].Answer").unwrap_or_default();
    let _ = j_resp.string_of("Questions[i].QuestionType").unwrap_or_default();
    let _ = j_resp.bool_of("Questions[i].OfficeUse");
    let _ = j_resp.string_of("Questions[i].OfficeNote").unwrap_or_default();
    j = 0;
    count_j = j_resp.size_of_array("Questions[i].Rows");
    while j < count_j {
        j_resp.set_j(j);
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("Questions[i].ColumnNames");
    while j < count_j {
        j_resp.set_j(j);
        j = j + 1;
    }

    i = i + 1;
}

i = 0;
count_i = j_resp.size_of_array("ConsentForms");
while i < count_i {
    j_resp.set_i(i);
    id = j_resp.string_of("ConsentForms[i].Id").unwrap_or_default();
    let _ = j_resp.string_of("ConsentForms[i].Name").unwrap_or_default();
    let _ = j_resp.string_of("ConsentForms[i].DocumentType").unwrap_or_default();
    let _ = j_resp.bool_of("ConsentForms[i].Signed");
    date_submitted = j_resp.int_of("ConsentForms[i].DateSubmitted");
    i = i + 1;
}