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 <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

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

    CkJsonObjectW json;
    json.UpdateString(L"QuestionnaireId",L"00000000-0000-0000-0000-000000000000");
    json.UpdateInt(L"ClientId",123);
    json.UpdateString(L"ClientName",L"Dexter Morgan");
    json.UpdateString(L"ClientEmail",L"dexter@email.com");
    json.UpdateString(L"ClientPhone",L"2222222222");
    json.UpdateString(L"PractitionerId",L"00000000-0000-0000-0000-000000000000");

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

    CkHttpResponseW resp;
    success = http.HttpJson(L"POST",L"https://intakeq.com/api/v1/intakes/send",json,L"application/json",resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp.GetBodySb(sbResponseBody);
    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

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

    int respStatusCode = resp.get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp.header());
        wprintf(L"Failed.\n");
        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.

    const wchar_t *Text = 0;
    const wchar_t *Answer = 0;
    const wchar_t *QuestionType = 0;
    bool OfficeUse;
    const wchar_t *OfficeNote = 0;
    int j;
    int count_j;
    const wchar_t *Name = 0;
    const wchar_t *DocumentType = 0;
    bool Signed;

    const wchar_t *Id = jResp.stringOf(L"Id");
    const wchar_t *ClientName = jResp.stringOf(L"ClientName");
    const wchar_t *ClientEmail = jResp.stringOf(L"ClientEmail");
    int ClientId = jResp.IntOf(L"ClientId");
    const wchar_t *Status = jResp.stringOf(L"Status");
    int DateCreated = jResp.IntOf(L"DateCreated");
    int DateSubmitted = jResp.IntOf(L"DateSubmitted");
    const wchar_t *QuestionnaireName = jResp.stringOf(L"QuestionnaireName");
    const wchar_t *Practitioner = jResp.stringOf(L"Practitioner");
    const wchar_t *PractitionerName = jResp.stringOf(L"PractitionerName");
    const wchar_t *AppointmentId = jResp.stringOf(L"AppointmentId");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"Questions");
    while (i < count_i) {
        jResp.put_I(i);
        Id = jResp.stringOf(L"Questions[i].Id");
        Text = jResp.stringOf(L"Questions[i].Text");
        Answer = jResp.stringOf(L"Questions[i].Answer");
        QuestionType = jResp.stringOf(L"Questions[i].QuestionType");
        OfficeUse = jResp.BoolOf(L"Questions[i].OfficeUse");
        OfficeNote = jResp.stringOf(L"Questions[i].OfficeNote");
        j = 0;
        count_j = jResp.SizeOfArray(L"Questions[i].Rows");
        while (j < count_j) {
            jResp.put_J(j);
            j = j + 1;
        }

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

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"ConsentForms");
    while (i < count_i) {
        jResp.put_I(i);
        Id = jResp.stringOf(L"ConsentForms[i].Id");
        Name = jResp.stringOf(L"ConsentForms[i].Name");
        DocumentType = jResp.stringOf(L"ConsentForms[i].DocumentType");
        Signed = jResp.BoolOf(L"ConsentForms[i].Signed");
        DateSubmitted = jResp.IntOf(L"ConsentForms[i].DateSubmitted");
        i = i + 1;
    }
    }