Sample code for 30+ languages & platforms
Lua

IntakeQ: Send a Questionnaire

See more IntakeQ Examples

Send an intake package using the API.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local 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"
-- }

local json = chilkat.JsonObject.new()
json:update_string("QuestionnaireId", "00000000-0000-0000-0000-000000000000")
json:update_int("ClientId", 123)
json:update_string("ClientName", "Dexter Morgan")
json:update_string("ClientEmail", "dexter@email.com")
json:update_string("ClientPhone", "2222222222")
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")

local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://intakeq.com/api/v1/intakes/send", json, "application/json", resp)
if not success then
    print(http.last_error_text)
    return
end

local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    return
end

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

local Text = ""
local Answer = ""
local QuestionType = ""
local OfficeUse = false
local OfficeNote = ""
local j = 0
local count_j = 0
local Name = ""
local DocumentType = ""
local Signed = false

local Id = jResp:string_of("Id")
local ClientName = jResp:string_of("ClientName")
local ClientEmail = jResp:string_of("ClientEmail")
local ClientId = jResp:int_of("ClientId")
local Status = jResp:string_of("Status")
local DateCreated = jResp:int_of("DateCreated")
local DateSubmitted = jResp:int_of("DateSubmitted")
local QuestionnaireName = jResp:string_of("QuestionnaireName")
local Practitioner = jResp:string_of("Practitioner")
local PractitionerName = jResp:string_of("PractitionerName")
local AppointmentId = jResp:string_of("AppointmentId")
local i = 0
local count_i = jResp:size_of_array("Questions")
while i < count_i do
    jResp.i = i
    Id = jResp:string_of("Questions[i].Id")
    Text = jResp:string_of("Questions[i].Text")
    Answer = jResp:string_of("Questions[i].Answer")
    QuestionType = jResp:string_of("Questions[i].QuestionType")
    OfficeUse = jResp:bool_of("Questions[i].OfficeUse")
    OfficeNote = jResp:string_of("Questions[i].OfficeNote")
    j = 0
    count_j = jResp:size_of_array("Questions[i].Rows")
    while j < count_j do
        jResp.j = j
        j = j + 1
    end

    j = 0
    count_j = jResp:size_of_array("Questions[i].ColumnNames")
    while j < count_j do
        jResp.j = j
        j = j + 1
    end

    i = i + 1
end

i = 0
count_i = jResp:size_of_array("ConsentForms")
while i < count_i do
    jResp.i = i
    Id = jResp:string_of("ConsentForms[i].Id")
    Name = jResp:string_of("ConsentForms[i].Name")
    DocumentType = jResp:string_of("ConsentForms[i].DocumentType")
    Signed = jResp:bool_of("ConsentForms[i].Signed")
    DateSubmitted = jResp:int_of("ConsentForms[i].DateSubmitted")
    i = i + 1
end