Delphi DLL
Delphi DLL
IntakeQ: Send a Questionnaire
See more IntakeQ Examples
Send an intake package using the API.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, HttpResponse, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
Text: PWideChar;
Answer: PWideChar;
QuestionType: PWideChar;
OfficeUse: Boolean;
OfficeNote: PWideChar;
j: Integer;
count_j: Integer;
Name: PWideChar;
DocumentType: PWideChar;
Signed: Boolean;
Id: PWideChar;
ClientName: PWideChar;
ClientEmail: PWideChar;
ClientId: Integer;
Status: PWideChar;
DateCreated: Integer;
DateSubmitted: Integer;
QuestionnaireName: PWideChar;
Practitioner: PWideChar;
PractitionerName: PWideChar;
AppointmentId: PWideChar;
i: Integer;
count_i: Integer;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
// 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"
// }
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'QuestionnaireId','00000000-0000-0000-0000-000000000000');
CkJsonObject_UpdateInt(json,'ClientId',123);
CkJsonObject_UpdateString(json,'ClientName','Dexter Morgan');
CkJsonObject_UpdateString(json,'ClientEmail','dexter@email.com');
CkJsonObject_UpdateString(json,'ClientPhone','2222222222');
CkJsonObject_UpdateString(json,'PractitionerId','00000000-0000-0000-0000-000000000000');
CkHttp_SetRequestHeader(http,'Content-Type','application/json');
CkHttp_SetRequestHeader(http,'X-Auth-Key','xxxxxxxxxxxxxxxxxxxxxxxxx');
resp := CkHttpResponse_Create();
success := CkHttp_HttpJson(http,'POST','https://intakeq.com/api/v1/intakes/send',json,'application/json',resp);
if (success = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));
respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkHttpResponse__header(resp));
Memo1.Lines.Add('Failed.');
Exit;
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
Id := CkJsonObject__stringOf(jResp,'Id');
ClientName := CkJsonObject__stringOf(jResp,'ClientName');
ClientEmail := CkJsonObject__stringOf(jResp,'ClientEmail');
ClientId := CkJsonObject_IntOf(jResp,'ClientId');
Status := CkJsonObject__stringOf(jResp,'Status');
DateCreated := CkJsonObject_IntOf(jResp,'DateCreated');
DateSubmitted := CkJsonObject_IntOf(jResp,'DateSubmitted');
QuestionnaireName := CkJsonObject__stringOf(jResp,'QuestionnaireName');
Practitioner := CkJsonObject__stringOf(jResp,'Practitioner');
PractitionerName := CkJsonObject__stringOf(jResp,'PractitionerName');
AppointmentId := CkJsonObject__stringOf(jResp,'AppointmentId');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'Questions');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
Id := CkJsonObject__stringOf(jResp,'Questions[i].Id');
Text := CkJsonObject__stringOf(jResp,'Questions[i].Text');
Answer := CkJsonObject__stringOf(jResp,'Questions[i].Answer');
QuestionType := CkJsonObject__stringOf(jResp,'Questions[i].QuestionType');
OfficeUse := CkJsonObject_BoolOf(jResp,'Questions[i].OfficeUse');
OfficeNote := CkJsonObject__stringOf(jResp,'Questions[i].OfficeNote');
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'Questions[i].Rows');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'Questions[i].ColumnNames');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
j := j + 1;
end;
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'ConsentForms');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
Id := CkJsonObject__stringOf(jResp,'ConsentForms[i].Id');
Name := CkJsonObject__stringOf(jResp,'ConsentForms[i].Name');
DocumentType := CkJsonObject__stringOf(jResp,'ConsentForms[i].DocumentType');
Signed := CkJsonObject_BoolOf(jResp,'ConsentForms[i].Signed');
DateSubmitted := CkJsonObject_IntOf(jResp,'ConsentForms[i].DateSubmitted');
i := i + 1;
end;
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkHttpResponse_Dispose(resp);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
end;