Sample code for 30+ languages & platforms
Java

IntakeQ: Send a Questionnaire

See more IntakeQ Examples

Send an intake package using the API.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

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

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

        JsonObject 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");

        HttpResponse resp = new HttpResponse();
        try {
            http.httpJson("POST", "https://intakeq.com/api/v1/intakes/send", json, "application/json", resp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        StringBuilder sbResponseBody = new StringBuilder();
        resp.getBodySb(sbResponseBody);
        JsonObject jResp = new JsonObject();
        jResp.loadSb(sbResponseBody);
        jResp.setEmitCompact(false);

        System.out.println("Response Body:");
        System.out.println(jResp.emit());

        int respStatusCode = resp.getStatusCode();
        System.out.println("Response Status Code = " + respStatusCode);
        if (respStatusCode >= 400) {
            System.out.println("Response Header:");
            System.out.println(resp.getHeader());
            System.out.println("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

        String Text = "";
        String Answer = "";
        String QuestionType = "";
        boolean OfficeUse = false;
        String OfficeNote = "";
        int j = 0;
        int count_j = 0;
        String Name = "";
        String DocumentType = "";
        boolean Signed = false;

        String Id = jResp.stringOf("Id");
        String ClientName = jResp.stringOf("ClientName");
        String ClientEmail = jResp.stringOf("ClientEmail");
        int ClientId = jResp.intOf("ClientId");
        String Status = jResp.stringOf("Status");
        int DateCreated = jResp.intOf("DateCreated");
        int DateSubmitted = jResp.intOf("DateSubmitted");
        String QuestionnaireName = jResp.stringOf("QuestionnaireName");
        String Practitioner = jResp.stringOf("Practitioner");
        String PractitionerName = jResp.stringOf("PractitionerName");
        String AppointmentId = jResp.stringOf("AppointmentId");
        int i = 0;
        int count_i = jResp.sizeOfArray("Questions");
        while (i < count_i) {
            jResp.setI(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");
            while (j < count_j) {
                jResp.setJ(j);
                j = j + 1;
            }

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

            i = i + 1;
        }

        i = 0;
        count_i = jResp.sizeOfArray("ConsentForms");
        while (i < count_i) {
            jResp.setI(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");
            i = i + 1;
        }
    }
}