Sample code for 30+ languages & platforms
DataFlex

IntakeQ: Send a Questionnaire

See more IntakeQ Examples

Send an intake package using the API.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sText
    String sAnswer
    String sQuestionType
    Boolean iOfficeUse
    String sOfficeNote
    Integer j
    Integer iCount_j
    String sName
    String sDocumentType
    Boolean iSigned
    String sId
    String sClientName
    String sClientEmail
    Integer iClientId
    String sStatus
    Integer iDateCreated
    Integer iDateSubmitted
    String sQuestionnaireName
    String sPractitioner
    String sPractitionerName
    String sAppointmentId
    Integer i
    Integer iCount_i
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "QuestionnaireId" "00000000-0000-0000-0000-000000000000" To iSuccess
    Get ComUpdateInt Of hoJson "ClientId" 123 To iSuccess
    Get ComUpdateString Of hoJson "ClientName" "Dexter Morgan" To iSuccess
    Get ComUpdateString Of hoJson "ClientEmail" "dexter@email.com" To iSuccess
    Get ComUpdateString Of hoJson "ClientPhone" "2222222222" To iSuccess
    Get ComUpdateString Of hoJson "PractitionerId" "00000000-0000-0000-0000-000000000000" To iSuccess

    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
    Send ComSetRequestHeader To hoHttp "X-Auth-Key" "xxxxxxxxxxxxxxxxxxxxxxxxx"

    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoResp to vResp
    Get ComHttpJson Of hoHttp "POST" "https://intakeq.com/api/v1/intakes/send" vJson "application/json" vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

    // 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

    Get ComStringOf Of hoJResp "Id" To sId
    Get ComStringOf Of hoJResp "ClientName" To sClientName
    Get ComStringOf Of hoJResp "ClientEmail" To sClientEmail
    Get ComIntOf Of hoJResp "ClientId" To iClientId
    Get ComStringOf Of hoJResp "Status" To sStatus
    Get ComIntOf Of hoJResp "DateCreated" To iDateCreated
    Get ComIntOf Of hoJResp "DateSubmitted" To iDateSubmitted
    Get ComStringOf Of hoJResp "QuestionnaireName" To sQuestionnaireName
    Get ComStringOf Of hoJResp "Practitioner" To sPractitioner
    Get ComStringOf Of hoJResp "PractitionerName" To sPractitionerName
    Get ComStringOf Of hoJResp "AppointmentId" To sAppointmentId
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "Questions" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "Questions[i].Id" To sId
        Get ComStringOf Of hoJResp "Questions[i].Text" To sText
        Get ComStringOf Of hoJResp "Questions[i].Answer" To sAnswer
        Get ComStringOf Of hoJResp "Questions[i].QuestionType" To sQuestionType
        Get ComBoolOf Of hoJResp "Questions[i].OfficeUse" To iOfficeUse
        Get ComStringOf Of hoJResp "Questions[i].OfficeNote" To sOfficeNote
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "Questions[i].Rows" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "Questions[i].ColumnNames" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "ConsentForms" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "ConsentForms[i].Id" To sId
        Get ComStringOf Of hoJResp "ConsentForms[i].Name" To sName
        Get ComStringOf Of hoJResp "ConsentForms[i].DocumentType" To sDocumentType
        Get ComBoolOf Of hoJResp "ConsentForms[i].Signed" To iSigned
        Get ComIntOf Of hoJResp "ConsentForms[i].DateSubmitted" To iDateSubmitted
        Move (i + 1) To i
    Loop



End_Procedure