Visual FoxPro
Visual FoxPro
IntakeQ: Send a Questionnaire
See more IntakeQ Examples
Send an intake package using the API.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJson
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcText
LOCAL lcAnswer
LOCAL lcQuestionType
LOCAL lnOfficeUse
LOCAL lcOfficeNote
LOCAL j
LOCAL lnCount_j
LOCAL lcName
LOCAL lcDocumentType
LOCAL lnSigned
LOCAL lcId
LOCAL lcClientName
LOCAL lcClientEmail
LOCAL lnClientId
LOCAL lcStatus
LOCAL lnDateCreated
LOCAL lnDateSubmitted
LOCAL lcQuestionnaireName
LOCAL lcPractitioner
LOCAL lcPractitionerName
LOCAL lcAppointmentId
LOCAL i
LOCAL lnCount_i
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = 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"
* }
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("QuestionnaireId","00000000-0000-0000-0000-000000000000")
loJson.UpdateInt("ClientId",123)
loJson.UpdateString("ClientName","Dexter Morgan")
loJson.UpdateString("ClientEmail","dexter@email.com")
loJson.UpdateString("ClientPhone","2222222222")
loJson.UpdateString("PractitionerId","00000000-0000-0000-0000-000000000000")
loHttp.SetRequestHeader("Content-Type","application/json")
loHttp.SetRequestHeader("X-Auth-Key","xxxxxxxxxxxxxxxxxxxxxxxxx")
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpJson("POST","https://intakeq.com/api/v1/intakes/send",loJson,"application/json",loResp)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
RELEASE loResp
CANCEL
ENDIF
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loResp.Header
? "Failed."
RELEASE loHttp
RELEASE loJson
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
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
lcId = loJResp.StringOf("Id")
lcClientName = loJResp.StringOf("ClientName")
lcClientEmail = loJResp.StringOf("ClientEmail")
lnClientId = loJResp.IntOf("ClientId")
lcStatus = loJResp.StringOf("Status")
lnDateCreated = loJResp.IntOf("DateCreated")
lnDateSubmitted = loJResp.IntOf("DateSubmitted")
lcQuestionnaireName = loJResp.StringOf("QuestionnaireName")
lcPractitioner = loJResp.StringOf("Practitioner")
lcPractitionerName = loJResp.StringOf("PractitionerName")
lcAppointmentId = loJResp.StringOf("AppointmentId")
i = 0
lnCount_i = loJResp.SizeOfArray("Questions")
DO WHILE i < lnCount_i
loJResp.I = i
lcId = loJResp.StringOf("Questions[i].Id")
lcText = loJResp.StringOf("Questions[i].Text")
lcAnswer = loJResp.StringOf("Questions[i].Answer")
lcQuestionType = loJResp.StringOf("Questions[i].QuestionType")
lnOfficeUse = loJResp.BoolOf("Questions[i].OfficeUse")
lcOfficeNote = loJResp.StringOf("Questions[i].OfficeNote")
j = 0
lnCount_j = loJResp.SizeOfArray("Questions[i].Rows")
DO WHILE j < lnCount_j
loJResp.J = j
j = j + 1
ENDDO
j = 0
lnCount_j = loJResp.SizeOfArray("Questions[i].ColumnNames")
DO WHILE j < lnCount_j
loJResp.J = j
j = j + 1
ENDDO
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("ConsentForms")
DO WHILE i < lnCount_i
loJResp.I = i
lcId = loJResp.StringOf("ConsentForms[i].Id")
lcName = loJResp.StringOf("ConsentForms[i].Name")
lcDocumentType = loJResp.StringOf("ConsentForms[i].DocumentType")
lnSigned = loJResp.BoolOf("ConsentForms[i].Signed")
lnDateSubmitted = loJResp.IntOf("ConsentForms[i].DateSubmitted")
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loJson
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp