Sample code for 30+ languages & platforms
Perl

IntakeQ: Send a Questionnaire

See more IntakeQ Examples

Send an intake package using the API.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

$http = chilkat::CkHttp->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"
# }

$json = chilkat::CkJsonObject->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");

$resp = chilkat::CkHttpResponse->new();
$success = $http->HttpJson("POST","https://intakeq.com/api/v1/intakes/send",$json,"application/json",$resp);
if ($success == 0) {
    print $http->lastErrorText() . "\r\n";
    exit;
}

$sbResponseBody = chilkat::CkStringBuilder->new();
$resp->GetBodySb($sbResponseBody);
$jResp = chilkat::CkJsonObject->new();
$jResp->LoadSb($sbResponseBody);
$jResp->put_EmitCompact(0);

print "Response Body:" . "\r\n";
print $jResp->emit() . "\r\n";

$respStatusCode = $resp->get_StatusCode();
print "Response Status Code = " . $respStatusCode . "\r\n";
if ($respStatusCode >= 400) {
    print "Response Header:" . "\r\n";
    print $resp->header() . "\r\n";
    print "Failed." . "\r\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

$Id = $jResp->stringOf("Id");
$ClientName = $jResp->stringOf("ClientName");
$ClientEmail = $jResp->stringOf("ClientEmail");
$ClientId = $jResp->IntOf("ClientId");
$Status = $jResp->stringOf("Status");
$DateCreated = $jResp->IntOf("DateCreated");
$DateSubmitted = $jResp->IntOf("DateSubmitted");
$QuestionnaireName = $jResp->stringOf("QuestionnaireName");
$Practitioner = $jResp->stringOf("Practitioner");
$PractitionerName = $jResp->stringOf("PractitionerName");
$AppointmentId = $jResp->stringOf("AppointmentId");
$i = 0;
$count_i = $jResp->SizeOfArray("Questions");
while ($i < $count_i) {
    $jResp->put_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->put_J($j);
        $j = $j + 1;
    }

    $j = 0;
    $count_j = $jResp->SizeOfArray("Questions[i].ColumnNames");
    while ($j < $count_j) {
        $jResp->put_J($j);
        $j = $j + 1;
    }

    $i = $i + 1;
}

$i = 0;
$count_i = $jResp->SizeOfArray("ConsentForms");
while ($i < $count_i) {
    $jResp->put_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;
}