Sample code for 30+ languages & platforms
Unicode C

IntakeQ: Send a Questionnaire

See more IntakeQ Examples

Send an intake package using the API.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *Text;
    const wchar_t *Answer;
    const wchar_t *QuestionType;
    BOOL OfficeUse;
    const wchar_t *OfficeNote;
    int j;
    int count_j;
    const wchar_t *Name;
    const wchar_t *DocumentType;
    BOOL Signed;
    const wchar_t *Id;
    const wchar_t *ClientName;
    const wchar_t *ClientEmail;
    int ClientId;
    const wchar_t *Status;
    int DateCreated;
    int DateSubmitted;
    const wchar_t *QuestionnaireName;
    const wchar_t *Practitioner;
    const wchar_t *PractitionerName;
    const wchar_t *AppointmentId;
    int i;
    int count_i;

    success = FALSE;

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

    http = CkHttpW_Create();

    // 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 = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"QuestionnaireId",L"00000000-0000-0000-0000-000000000000");
    CkJsonObjectW_UpdateInt(json,L"ClientId",123);
    CkJsonObjectW_UpdateString(json,L"ClientName",L"Dexter Morgan");
    CkJsonObjectW_UpdateString(json,L"ClientEmail",L"dexter@email.com");
    CkJsonObjectW_UpdateString(json,L"ClientPhone",L"2222222222");
    CkJsonObjectW_UpdateString(json,L"PractitionerId",L"00000000-0000-0000-0000-000000000000");

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
    CkHttpW_SetRequestHeader(http,L"X-Auth-Key",L"xxxxxxxxxxxxxxxxxxxxxxxxx");

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpJson(http,L"POST",L"https://intakeq.com/api/v1/intakes/send",json,L"application/json",resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);
    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkHttpResponseW_Dispose(resp);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    Id = CkJsonObjectW_stringOf(jResp,L"Id");
    ClientName = CkJsonObjectW_stringOf(jResp,L"ClientName");
    ClientEmail = CkJsonObjectW_stringOf(jResp,L"ClientEmail");
    ClientId = CkJsonObjectW_IntOf(jResp,L"ClientId");
    Status = CkJsonObjectW_stringOf(jResp,L"Status");
    DateCreated = CkJsonObjectW_IntOf(jResp,L"DateCreated");
    DateSubmitted = CkJsonObjectW_IntOf(jResp,L"DateSubmitted");
    QuestionnaireName = CkJsonObjectW_stringOf(jResp,L"QuestionnaireName");
    Practitioner = CkJsonObjectW_stringOf(jResp,L"Practitioner");
    PractitionerName = CkJsonObjectW_stringOf(jResp,L"PractitionerName");
    AppointmentId = CkJsonObjectW_stringOf(jResp,L"AppointmentId");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"Questions");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        Id = CkJsonObjectW_stringOf(jResp,L"Questions[i].Id");
        Text = CkJsonObjectW_stringOf(jResp,L"Questions[i].Text");
        Answer = CkJsonObjectW_stringOf(jResp,L"Questions[i].Answer");
        QuestionType = CkJsonObjectW_stringOf(jResp,L"Questions[i].QuestionType");
        OfficeUse = CkJsonObjectW_BoolOf(jResp,L"Questions[i].OfficeUse");
        OfficeNote = CkJsonObjectW_stringOf(jResp,L"Questions[i].OfficeNote");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"Questions[i].Rows");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"Questions[i].ColumnNames");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"ConsentForms");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        Id = CkJsonObjectW_stringOf(jResp,L"ConsentForms[i].Id");
        Name = CkJsonObjectW_stringOf(jResp,L"ConsentForms[i].Name");
        DocumentType = CkJsonObjectW_stringOf(jResp,L"ConsentForms[i].DocumentType");
        Signed = CkJsonObjectW_BoolOf(jResp,L"ConsentForms[i].Signed");
        DateSubmitted = CkJsonObjectW_IntOf(jResp,L"ConsentForms[i].DateSubmitted");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkHttpResponseW_Dispose(resp);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }