Swift
Swift
IntakeQ: Send a Questionnaire
See more IntakeQ Examples
Send an intake package using the API.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// 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 = CkoJsonObject()!
json.updateString(jsonPath: "QuestionnaireId", value: "00000000-0000-0000-0000-000000000000")
json.updateInt(jsonPath: "ClientId", value: 123)
json.updateString(jsonPath: "ClientName", value: "Dexter Morgan")
json.updateString(jsonPath: "ClientEmail", value: "dexter@email.com")
json.updateString(jsonPath: "ClientPhone", value: "2222222222")
json.updateString(jsonPath: "PractitionerId", value: "00000000-0000-0000-0000-000000000000")
http.setRequestHeader(name: "Content-Type", value: "application/json")
http.setRequestHeader(name: "X-Auth-Key", value: "xxxxxxxxxxxxxxxxxxxxxxxxx")
let resp = CkoHttpResponse()!
success = http.httpJson(verb: "POST", url: "https://intakeq.com/api/v1/intakes/send", json: json, contentType: "application/json", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
let sbResponseBody = CkoStringBuilder()!
resp.getBodySb(sb: sbResponseBody)
let jResp = CkoJsonObject()!
jResp.loadSb(sb: sbResponseBody)
jResp.emitCompact = false
print("Response Body:")
print("\(jResp.emit()!)")
var respStatusCode: Int = resp.statusCode.intValue
print("Response Status Code = \(respStatusCode)")
if respStatusCode >= 400 {
print("Response Header:")
print("\(resp.header!)")
print("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
var Text: String?
var Answer: String?
var QuestionType: String?
var OfficeUse: Bool
var OfficeNote: String?
var j: Int
var count_j: Int
var Name: String?
var DocumentType: String?
var Signed: Bool
var Id: String? = jResp.string(of: "Id")
var ClientName: String? = jResp.string(of: "ClientName")
var ClientEmail: String? = jResp.string(of: "ClientEmail")
var ClientId: Int = jResp.int(of: "ClientId").intValue
var Status: String? = jResp.string(of: "Status")
var DateCreated: Int = jResp.int(of: "DateCreated").intValue
var DateSubmitted: Int = jResp.int(of: "DateSubmitted").intValue
var QuestionnaireName: String? = jResp.string(of: "QuestionnaireName")
var Practitioner: String? = jResp.string(of: "Practitioner")
var PractitionerName: String? = jResp.string(of: "PractitionerName")
var AppointmentId: String? = jResp.string(of: "AppointmentId")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "Questions").intValue
while i < count_i {
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(ofArray: "Questions[i].Rows").intValue
while j < count_j {
jResp.j = j
j = j + 1
}
j = 0
count_j = jResp.size(ofArray: "Questions[i].ColumnNames").intValue
while j < count_j {
jResp.j = j
j = j + 1
}
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "ConsentForms").intValue
while i < count_i {
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").intValue
i = i + 1
}
}