Perl
Perl
IntakeQ: Send a Questionnaire
See more IntakeQ Examples
Send an intake package using the API.Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
my $http = Chilkat2::Http->new;
# 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"
# }
my $json = Chilkat2::JsonObject->new;
$json->UpdateString('QuestionnaireId', '00000000-0000-0000-0000-000000000000');
$json->UpdateInt('ClientId', 123);
$json->UpdateString('ClientName', 'Dexter Morgan');
$json->UpdateString('ClientEmail', 'dexter@email.com');
$json->UpdateString('ClientPhone', '2222222222');
$json->UpdateString('PractitionerId', '00000000-0000-0000-0000-000000000000');
$http->SetRequestHeader('Content-Type', 'application/json');
$http->SetRequestHeader('X-Auth-Key', 'xxxxxxxxxxxxxxxxxxxxxxxxx');
my $resp = Chilkat2::HttpResponse->new;
my $success = $http->HttpJson('POST', 'https://intakeq.com/api/v1/intakes/send', $json, 'application/json', $resp);
if (!$success) {
print $http->LastErrorText, "\n";
exit;
}
my $sbResponseBody = Chilkat2::StringBuilder->new;
$resp->GetBodySb($sbResponseBody);
my $jResp = Chilkat2::JsonObject->new;
$jResp->LoadSb($sbResponseBody);
$jResp->EmitCompact(0);
print "Response Body:\n";
print $jResp->Emit(), "\n";
my $respStatusCode = $resp->StatusCode;
print 'Response Status Code = ', $respStatusCode, "\n";
if ($respStatusCode >= 400) {
print "Response Header:\n";
print $resp->Header, "\n";
print "Failed.\n";
exit;
}
# 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
my $Text = '';
my $Answer = '';
my $QuestionType = '';
my $OfficeUse = 0;
my $OfficeNote = '';
my $j = 0;
my $count_j = 0;
my $Name = '';
my $DocumentType = '';
my $Signed = 0;
my $Id = $jResp->StringOf('Id');
my $ClientName = $jResp->StringOf('ClientName');
my $ClientEmail = $jResp->StringOf('ClientEmail');
my $ClientId = $jResp->IntOf('ClientId');
my $Status = $jResp->StringOf('Status');
my $DateCreated = $jResp->IntOf('DateCreated');
my $DateSubmitted = $jResp->IntOf('DateSubmitted');
my $QuestionnaireName = $jResp->StringOf('QuestionnaireName');
my $Practitioner = $jResp->StringOf('Practitioner');
my $PractitionerName = $jResp->StringOf('PractitionerName');
my $AppointmentId = $jResp->StringOf('AppointmentId');
my $i = 0;
my $count_i = $jResp->SizeOfArray('Questions');
while ($i < $count_i) {
$jResp->I($i);
$Id = $jResp->StringOf('Questions[i].Id');
$Text = $jResp->StringOf('Questions[i].Text');
$Answer = $jResp->StringOf('Questions[i].Answer');
$QuestionType = $jResp->StringOf('Questions[i].QuestionType');
$OfficeUse = $jResp->BoolOf('Questions[i].OfficeUse');
$OfficeNote = $jResp->StringOf('Questions[i].OfficeNote');
$j = 0;
$count_j = $jResp->SizeOfArray('Questions[i].Rows');
while ($j < $count_j) {
$jResp->J($j);
$j = $j + 1;
}
$j = 0;
$count_j = $jResp->SizeOfArray('Questions[i].ColumnNames');
while ($j < $count_j) {
$jResp->J($j);
$j = $j + 1;
}
$i = $i + 1;
}
$i = 0;
$count_i = $jResp->SizeOfArray('ConsentForms');
while ($i < $count_i) {
$jResp->I($i);
$Id = $jResp->StringOf('ConsentForms[i].Id');
$Name = $jResp->StringOf('ConsentForms[i].Name');
$DocumentType = $jResp->StringOf('ConsentForms[i].DocumentType');
$Signed = $jResp->BoolOf('ConsentForms[i].Signed');
$DateSubmitted = $jResp->IntOf('ConsentForms[i].DateSubmitted');
$i = $i + 1;
}