Xbase++
Xbase++
IntakeQ: Send a Questionnaire
See more IntakeQ Examples
Send an intake package using the API.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cText
LOCAL cAnswer
LOCAL cQuestionType
LOCAL nOfficeUse
LOCAL cOfficeNote
LOCAL j
LOCAL nCount_j
LOCAL cName
LOCAL cDocumentType
LOCAL nSigned
LOCAL cId
LOCAL cClientName
LOCAL cClientEmail
LOCAL nClientId
LOCAL cStatus
LOCAL nDateCreated
LOCAL nDateSubmitted
LOCAL cQuestionnaireName
LOCAL cPractitioner
LOCAL cPractitionerName
LOCAL cAppointmentId
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// 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"
// }
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("QuestionnaireId", "00000000-0000-0000-0000-000000000000")
oJson:UpdateInt("ClientId", 123)
oJson:UpdateString("ClientName", "Dexter Morgan")
oJson:UpdateString("ClientEmail", "dexter@email.com")
oJson:UpdateString("ClientPhone", "2222222222")
oJson:UpdateString("PractitionerId", "00000000-0000-0000-0000-000000000000")
oHttp:SetRequestHeader("Content-Type", "application/json")
oHttp:SetRequestHeader("X-Auth-Key", "xxxxxxxxxxxxxxxxxxxxxxxxx")
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://intakeq.com/api/v1/intakes/send", oJson, "application/json", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJson:destroy()
oResp:destroy()
RETURN
ENDIF
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oResp:Header
? "Failed."
oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
// 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
cId := oJResp:StringOf("Id")
cClientName := oJResp:StringOf("ClientName")
cClientEmail := oJResp:StringOf("ClientEmail")
nClientId := oJResp:IntOf("ClientId")
cStatus := oJResp:StringOf("Status")
nDateCreated := oJResp:IntOf("DateCreated")
nDateSubmitted := oJResp:IntOf("DateSubmitted")
cQuestionnaireName := oJResp:StringOf("QuestionnaireName")
cPractitioner := oJResp:StringOf("Practitioner")
cPractitionerName := oJResp:StringOf("PractitionerName")
cAppointmentId := oJResp:StringOf("AppointmentId")
i := 0
nCount_i := oJResp:SizeOfArray("Questions")
DO WHILE i < nCount_i
oJResp:I := i
cId := oJResp:StringOf("Questions[i].Id")
cText := oJResp:StringOf("Questions[i].Text")
cAnswer := oJResp:StringOf("Questions[i].Answer")
cQuestionType := oJResp:StringOf("Questions[i].QuestionType")
nOfficeUse := oJResp:BoolOf("Questions[i].OfficeUse")
cOfficeNote := oJResp:StringOf("Questions[i].OfficeNote")
j := 0
nCount_j := oJResp:SizeOfArray("Questions[i].Rows")
DO WHILE j < nCount_j
oJResp:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJResp:SizeOfArray("Questions[i].ColumnNames")
DO WHILE j < nCount_j
oJResp:J := j
j := j + 1
ENDDO
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("ConsentForms")
DO WHILE i < nCount_i
oJResp:I := i
cId := oJResp:StringOf("ConsentForms[i].Id")
cName := oJResp:StringOf("ConsentForms[i].Name")
cDocumentType := oJResp:StringOf("ConsentForms[i].DocumentType")
nSigned := oJResp:BoolOf("ConsentForms[i].Signed")
nDateSubmitted := oJResp:IntOf("ConsentForms[i].DateSubmitted")
i := i + 1
ENDDO
oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()