Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) IntakeQ: Send a QuestionnaireSee more IntakeQ ExamplesSend an intake package using the API. For more information, see https://support.intakeq.com/article/31-intakeq-api#send-questionnaire
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; 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.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"QuestionnaireId","00000000-0000-0000-0000-000000000000") CkJsonObject::ckUpdateInt(json,"ClientId",123) CkJsonObject::ckUpdateString(json,"ClientName","Dexter Morgan") CkJsonObject::ckUpdateString(json,"ClientEmail","dexter@email.com") CkJsonObject::ckUpdateString(json,"ClientPhone","2222222222") CkJsonObject::ckUpdateString(json,"PractitionerId","00000000-0000-0000-0000-000000000000") CkHttp::ckSetRequestHeader(http,"Content-Type","application/json") CkHttp::ckSetRequestHeader(http,"X-Auth-Key","xxxxxxxxxxxxxxxxxxxxxxxxx") resp.i = CkHttp::ckPostJson3(http,"https://intakeq.com/api/v1/intakes/send","application/json",json) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; 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 Text.s Answer.s QuestionType.s OfficeUse.i OfficeNote.s j.i count_j.i Name.s DocumentType.s Signed.i Id.s = CkJsonObject::ckStringOf(jResp,"Id") ClientName.s = CkJsonObject::ckStringOf(jResp,"ClientName") ClientEmail.s = CkJsonObject::ckStringOf(jResp,"ClientEmail") ClientId.i = CkJsonObject::ckIntOf(jResp,"ClientId") Status.s = CkJsonObject::ckStringOf(jResp,"Status") DateCreated.i = CkJsonObject::ckIntOf(jResp,"DateCreated") DateSubmitted.i = CkJsonObject::ckIntOf(jResp,"DateSubmitted") QuestionnaireName.s = CkJsonObject::ckStringOf(jResp,"QuestionnaireName") Practitioner.s = CkJsonObject::ckStringOf(jResp,"Practitioner") PractitionerName.s = CkJsonObject::ckStringOf(jResp,"PractitionerName") AppointmentId.s = CkJsonObject::ckStringOf(jResp,"AppointmentId") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jResp,"Questions") While i < count_i CkJsonObject::setCkI(jResp, i) Id = CkJsonObject::ckStringOf(jResp,"Questions[i].Id") Text = CkJsonObject::ckStringOf(jResp,"Questions[i].Text") Answer = CkJsonObject::ckStringOf(jResp,"Questions[i].Answer") QuestionType = CkJsonObject::ckStringOf(jResp,"Questions[i].QuestionType") OfficeUse = CkJsonObject::ckBoolOf(jResp,"Questions[i].OfficeUse") OfficeNote = CkJsonObject::ckStringOf(jResp,"Questions[i].OfficeNote") j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"Questions[i].Rows") While j < count_j CkJsonObject::setCkJ(jResp, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"Questions[i].ColumnNames") While j < count_j CkJsonObject::setCkJ(jResp, j) j = j + 1 Wend i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"ConsentForms") While i < count_i CkJsonObject::setCkI(jResp, i) Id = CkJsonObject::ckStringOf(jResp,"ConsentForms[i].Id") Name = CkJsonObject::ckStringOf(jResp,"ConsentForms[i].Name") DocumentType = CkJsonObject::ckStringOf(jResp,"ConsentForms[i].DocumentType") Signed = CkJsonObject::ckBoolOf(jResp,"ConsentForms[i].Signed") DateSubmitted = CkJsonObject::ckIntOf(jResp,"ConsentForms[i].DateSubmitted") i = i + 1 Wend CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.