Objective-C
Objective-C
IntakeQ: Send a Questionnaire
See more IntakeQ Examples
Send an intake package using the API.Chilkat Objective-C Downloads
#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>
#import <CkoStringBuilder.h>
#import <NSString.h>
BOOL success = NO;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoHttp *http = [[CkoHttp alloc] init];
// 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"
// }
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"QuestionnaireId" value: @"00000000-0000-0000-0000-000000000000"];
[json UpdateInt: @"ClientId" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"ClientName" value: @"Dexter Morgan"];
[json UpdateString: @"ClientEmail" value: @"dexter@email.com"];
[json UpdateString: @"ClientPhone" value: @"2222222222"];
[json UpdateString: @"PractitionerId" value: @"00000000-0000-0000-0000-000000000000"];
[http SetRequestHeader: @"Content-Type" value: @"application/json"];
[http SetRequestHeader: @"X-Auth-Key" value: @"xxxxxxxxxxxxxxxxxxxxxxxxx"];
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
success = [http HttpJson: @"POST" url: @"https://intakeq.com/api/v1/intakes/send" json: json contentType: @"application/json" response: resp];
if (success == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
[resp GetBodySb: sbResponseBody];
CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;
NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);
int respStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
NSLog(@"%@",@"Response Header:");
NSLog(@"%@",resp.Header);
NSLog(@"%@",@"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
NSString *Text = 0;
NSString *Answer = 0;
NSString *QuestionType = 0;
BOOL OfficeUse;
NSString *OfficeNote = 0;
int j;
int count_j;
NSString *Name = 0;
NSString *DocumentType = 0;
BOOL Signed;
NSString *Id = [jResp StringOf: @"Id"];
NSString *ClientName = [jResp StringOf: @"ClientName"];
NSString *ClientEmail = [jResp StringOf: @"ClientEmail"];
int ClientId = [[jResp IntOf: @"ClientId"] intValue];
NSString *Status = [jResp StringOf: @"Status"];
int DateCreated = [[jResp IntOf: @"DateCreated"] intValue];
int DateSubmitted = [[jResp IntOf: @"DateSubmitted"] intValue];
NSString *QuestionnaireName = [jResp StringOf: @"QuestionnaireName"];
NSString *Practitioner = [jResp StringOf: @"Practitioner"];
NSString *PractitionerName = [jResp StringOf: @"PractitionerName"];
NSString *AppointmentId = [jResp StringOf: @"AppointmentId"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"Questions"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: 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"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
j = j + 1;
}
j = 0;
count_j = [[jResp SizeOfArray: @"Questions[i].ColumnNames"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"ConsentForms"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: 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"] intValue];
i = i + 1;
}