React Native
React Native
IntakeQ: Send a Questionnaire
See more IntakeQ Examples
Send an intake package using the API.Chilkat React Native Downloads
import { Http, HttpResponse, JsonObject, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new Http();
// 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"
// }
const json = new JsonObject();
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');
const resp = new HttpResponse();
try {
await http.httpJsonAsync('POST', 'https://intakeq.com/api/v1/intakes/send', json, 'application/json', resp);
} catch {
console.log(http.lastErrorText);
return;
}
const sbResponseBody = new StringBuilder();
resp.getBodySb(sbResponseBody);
const jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
jResp.emitCompact = false;
console.log('Response Body:');
console.log(jResp.emit());
const respStatusCode = resp.statusCode;
console.log(`Response Status Code = ${respStatusCode}`);
if (respStatusCode >= 400) {
console.log('Response Header:');
console.log(resp.header);
console.log('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
let text = '';
let answer = '';
let questionType = '';
let officeNote = '';
let j = 0;
let countJ = 0;
let name = '';
let documentType = '';
let id = jResp.stringOf('Id');
const clientName = jResp.stringOf('ClientName');
const clientEmail = jResp.stringOf('ClientEmail');
const clientId = jResp.intOf('ClientId');
const status = jResp.stringOf('Status');
const dateCreated = jResp.intOf('DateCreated');
let dateSubmitted = jResp.intOf('DateSubmitted');
const questionnaireName = jResp.stringOf('QuestionnaireName');
const practitioner = jResp.stringOf('Practitioner');
const practitionerName = jResp.stringOf('PractitionerName');
const appointmentId = jResp.stringOf('AppointmentId');
let i = 0;
let 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++;
}
}