Zig
Zig
IntakeQ: Send a Questionnaire
See more IntakeQ Examples
Send an intake package using the API.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// 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"
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("QuestionnaireId", "00000000-0000-0000-0000-000000000000") catch {};
json.updateInt("ClientId", 123) catch {};
json.updateString("ClientName", "Dexter Morgan") catch {};
json.updateString("ClientEmail", "dexter@email.com") catch {};
json.updateString("ClientPhone", "2222222222") catch {};
json.updateString("PractitionerId", "00000000-0000-0000-0000-000000000000") catch {};
http.setRequestHeader("Content-Type", "application/json");
http.setRequestHeader("X-Auth-Key", "xxxxxxxxxxxxxxxxxxxxxxxxx");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://intakeq.com/api/v1/intakes/send", json, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
resp.getBodySb(sb_response_body) catch {};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = resp.getStatusCode();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
std.debug.print("Failed.\n", .{});
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
var text: [:0]const u8 = "";
var answer: [:0]const u8 = "";
var question_type: [:0]const u8 = "";
var office_use: bool = false;
var office_note: [:0]const u8 = "";
var j: i32 = 0;
var count_j: i32 = 0;
var name: [:0]const u8 = "";
var document_type: [:0]const u8 = "";
var signed: bool = false;
var id: [:0]const u8 = try j_resp.stringOf(alloc, "Id");
_ = try j_resp.stringOf(alloc, "ClientName");
_ = try j_resp.stringOf(alloc, "ClientEmail");
_ = j_resp.intOf("ClientId");
_ = try j_resp.stringOf(alloc, "Status");
_ = j_resp.intOf("DateCreated");
var date_submitted: i32 = j_resp.intOf("DateSubmitted");
_ = try j_resp.stringOf(alloc, "QuestionnaireName");
_ = try j_resp.stringOf(alloc, "Practitioner");
_ = try j_resp.stringOf(alloc, "PractitionerName");
_ = try j_resp.stringOf(alloc, "AppointmentId");
var i: i32 = 0;
var count_i: i32 = j_resp.sizeOfArray("Questions");
while (i < count_i) {
j_resp.setI(i);
id = try j_resp.stringOf(alloc, "Questions[i].Id");
text = try j_resp.stringOf(alloc, "Questions[i].Text");
answer = try j_resp.stringOf(alloc, "Questions[i].Answer");
question_type = try j_resp.stringOf(alloc, "Questions[i].QuestionType");
office_use = j_resp.boolOf("Questions[i].OfficeUse");
office_note = try j_resp.stringOf(alloc, "Questions[i].OfficeNote");
j = 0;
count_j = j_resp.sizeOfArray("Questions[i].Rows");
while (j < count_j) {
j_resp.setJ(j);
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("Questions[i].ColumnNames");
while (j < count_j) {
j_resp.setJ(j);
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = j_resp.sizeOfArray("ConsentForms");
while (i < count_i) {
j_resp.setI(i);
id = try j_resp.stringOf(alloc, "ConsentForms[i].Id");
name = try j_resp.stringOf(alloc, "ConsentForms[i].Name");
document_type = try j_resp.stringOf(alloc, "ConsentForms[i].DocumentType");
signed = j_resp.boolOf("ConsentForms[i].Signed");
date_submitted = j_resp.intOf("ConsentForms[i].DateSubmitted");
i = i + 1;
}
}