Sample code for 30+ languages & platforms
Dart

IntakeQ: Send a Questionnaire

See more IntakeQ Examples

Send an intake package using the API.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final http = CkHttp();

  // 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"
  // }

  final json = CkJsonObject();
  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');

  final resp = CkHttpResponse();
  try {
    http.httpJson('POST', 'https://intakeq.com/api/v1/intakes/send', json, 'application/json', resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final sbResponseBody = CkStringBuilder();
  resp.getBodySb(sbResponseBody);
  final jResp = CkJsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  print('Response Body:');
  print(jResp.emit());

  final respStatusCode = resp.statusCode;
  print('Response Status Code = $respStatusCode');
  if (respStatusCode >= 400) {
    print('Response Header:');
    print(resp.header);
    print('Failed.');
    return;
  }

  // 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

  var text = '';
  var answer = '';
  var questionType = '';
  var officeNote = '';
  var j = 0;
  var countJ = 0;
  var name = '';
  var documentType = '';

  var id = jResp.stringOf('Id');
  final clientName = jResp.stringOf('ClientName');
  final clientEmail = jResp.stringOf('ClientEmail');
  final clientId = jResp.intOf('ClientId');
  final status = jResp.stringOf('Status');
  final dateCreated = jResp.intOf('DateCreated');
  var dateSubmitted = jResp.intOf('DateSubmitted');
  final questionnaireName = jResp.stringOf('QuestionnaireName');
  final practitioner = jResp.stringOf('Practitioner');
  final practitionerName = jResp.stringOf('PractitionerName');
  final appointmentId = jResp.stringOf('AppointmentId');
  var i = 0;
  var countI = jResp.sizeOfArray('Questions');
  while (i < countI) {
    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');
    jResp.boolOf('Questions[i].OfficeUse');
    officeNote = jResp.stringOf('Questions[i].OfficeNote');
    j = 0;
    countJ = jResp.sizeOfArray('Questions[i].Rows');
    while (j < countJ) {
      jResp.j = j;
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('Questions[i].ColumnNames');
    while (j < countJ) {
      jResp.j = j;
      j++;
    }

    i++;
  }

  i = 0;
  countI = jResp.sizeOfArray('ConsentForms');
  while (i < countI) {
    jResp.i = i;
    id = jResp.stringOf('ConsentForms[i].Id');
    name = jResp.stringOf('ConsentForms[i].Name');
    documentType = jResp.stringOf('ConsentForms[i].DocumentType');
    jResp.boolOf('ConsentForms[i].Signed');
    dateSubmitted = jResp.intOf('ConsentForms[i].DateSubmitted');
    i++;
  }
}