PowerBuilder
PowerBuilder
IntakeQ: Send a Questionnaire
See more IntakeQ Examples
Send an intake package using the API.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Text
string ls_Answer
string ls_QuestionType
integer li_OfficeUse
string ls_OfficeNote
integer j
integer li_Count_j
string ls_Name
string ls_DocumentType
integer li_Signed
string ls_Id
string ls_ClientName
string ls_ClientEmail
integer li_ClientId
string ls_Status
integer li_DateCreated
integer li_DateSubmitted
string ls_QuestionnaireName
string ls_Practitioner
string ls_PractitionerName
string ls_AppointmentId
integer i
integer li_Count_i
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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"
// }
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("QuestionnaireId","00000000-0000-0000-0000-000000000000")
loo_Json.UpdateInt("ClientId",123)
loo_Json.UpdateString("ClientName","Dexter Morgan")
loo_Json.UpdateString("ClientEmail","dexter@email.com")
loo_Json.UpdateString("ClientPhone","2222222222")
loo_Json.UpdateString("PractitionerId","00000000-0000-0000-0000-000000000000")
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Http.SetRequestHeader("X-Auth-Key","xxxxxxxxxxxxxxxxxxxxxxxxx")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpJson("POST","https://intakeq.com/api/v1/intakes/send",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_Resp
return
end if
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// 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
ls_Id = loo_JResp.StringOf("Id")
ls_ClientName = loo_JResp.StringOf("ClientName")
ls_ClientEmail = loo_JResp.StringOf("ClientEmail")
li_ClientId = loo_JResp.IntOf("ClientId")
ls_Status = loo_JResp.StringOf("Status")
li_DateCreated = loo_JResp.IntOf("DateCreated")
li_DateSubmitted = loo_JResp.IntOf("DateSubmitted")
ls_QuestionnaireName = loo_JResp.StringOf("QuestionnaireName")
ls_Practitioner = loo_JResp.StringOf("Practitioner")
ls_PractitionerName = loo_JResp.StringOf("PractitionerName")
ls_AppointmentId = loo_JResp.StringOf("AppointmentId")
i = 0
li_Count_i = loo_JResp.SizeOfArray("Questions")
do while i < li_Count_i
loo_JResp.I = i
ls_Id = loo_JResp.StringOf("Questions[i].Id")
ls_Text = loo_JResp.StringOf("Questions[i].Text")
ls_Answer = loo_JResp.StringOf("Questions[i].Answer")
ls_QuestionType = loo_JResp.StringOf("Questions[i].QuestionType")
li_OfficeUse = loo_JResp.BoolOf("Questions[i].OfficeUse")
ls_OfficeNote = loo_JResp.StringOf("Questions[i].OfficeNote")
j = 0
li_Count_j = loo_JResp.SizeOfArray("Questions[i].Rows")
do while j < li_Count_j
loo_JResp.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_JResp.SizeOfArray("Questions[i].ColumnNames")
do while j < li_Count_j
loo_JResp.J = j
j = j + 1
loop
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("ConsentForms")
do while i < li_Count_i
loo_JResp.I = i
ls_Id = loo_JResp.StringOf("ConsentForms[i].Id")
ls_Name = loo_JResp.StringOf("ConsentForms[i].Name")
ls_DocumentType = loo_JResp.StringOf("ConsentForms[i].DocumentType")
li_Signed = loo_JResp.BoolOf("ConsentForms[i].Signed")
li_DateSubmitted = loo_JResp.IntOf("ConsentForms[i].DateSubmitted")
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp