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
(C) 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
#include <C_CkHttp.h> #include <C_CkJsonObject.h> #include <C_CkHttpResponse.h> #include <C_CkStringBuilder.h> void ChilkatSample(void) { HCkHttp http; BOOL success; HCkJsonObject json; HCkHttpResponse resp; HCkStringBuilder sbResponseBody; HCkJsonObject jResp; int respStatusCode; const char *Text; const char *Answer; const char *QuestionType; BOOL OfficeUse; const char *OfficeNote; int j; int count_j; const char *Name; const char *DocumentType; BOOL Signed; const char *Id; const char *ClientName; const char *ClientEmail; int ClientId; const char *Status; int DateCreated; int DateSubmitted; const char *QuestionnaireName; const char *Practitioner; const char *PractitionerName; const char *AppointmentId; int i; int count_i; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttp_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 = CkJsonObject_Create(); CkJsonObject_UpdateString(json,"QuestionnaireId","00000000-0000-0000-0000-000000000000"); CkJsonObject_UpdateInt(json,"ClientId",123); CkJsonObject_UpdateString(json,"ClientName","Dexter Morgan"); CkJsonObject_UpdateString(json,"ClientEmail","dexter@email.com"); CkJsonObject_UpdateString(json,"ClientPhone","2222222222"); CkJsonObject_UpdateString(json,"PractitionerId","00000000-0000-0000-0000-000000000000"); CkHttp_SetRequestHeader(http,"Content-Type","application/json"); CkHttp_SetRequestHeader(http,"X-Auth-Key","xxxxxxxxxxxxxxxxxxxxxxxxx"); resp = CkHttp_PostJson3(http,"https://intakeq.com/api/v1/intakes/send","application/json",json); if (CkHttp_getLastMethodSuccess(http) == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkJsonObject_Dispose(json); return; } sbResponseBody = CkStringBuilder_Create(); CkHttpResponse_GetBodySb(resp,sbResponseBody); jResp = CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,FALSE); printf("Response Body:\n"); printf("%s\n",CkJsonObject_emit(jResp)); respStatusCode = CkHttpResponse_getStatusCode(resp); printf("Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { printf("Response Header:\n"); printf("%s\n",CkHttpResponse_header(resp)); printf("Failed.\n"); CkHttpResponse_Dispose(resp); CkHttp_Dispose(http); CkJsonObject_Dispose(json); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); return; } CkHttpResponse_Dispose(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 // 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 = CkJsonObject_stringOf(jResp,"Id"); ClientName = CkJsonObject_stringOf(jResp,"ClientName"); ClientEmail = CkJsonObject_stringOf(jResp,"ClientEmail"); ClientId = CkJsonObject_IntOf(jResp,"ClientId"); Status = CkJsonObject_stringOf(jResp,"Status"); DateCreated = CkJsonObject_IntOf(jResp,"DateCreated"); DateSubmitted = CkJsonObject_IntOf(jResp,"DateSubmitted"); QuestionnaireName = CkJsonObject_stringOf(jResp,"QuestionnaireName"); Practitioner = CkJsonObject_stringOf(jResp,"Practitioner"); PractitionerName = CkJsonObject_stringOf(jResp,"PractitionerName"); AppointmentId = CkJsonObject_stringOf(jResp,"AppointmentId"); i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"Questions"); while (i < count_i) { CkJsonObject_putI(jResp,i); Id = CkJsonObject_stringOf(jResp,"Questions[i].Id"); Text = CkJsonObject_stringOf(jResp,"Questions[i].Text"); Answer = CkJsonObject_stringOf(jResp,"Questions[i].Answer"); QuestionType = CkJsonObject_stringOf(jResp,"Questions[i].QuestionType"); OfficeUse = CkJsonObject_BoolOf(jResp,"Questions[i].OfficeUse"); OfficeNote = CkJsonObject_stringOf(jResp,"Questions[i].OfficeNote"); j = 0; count_j = CkJsonObject_SizeOfArray(jResp,"Questions[i].Rows"); while (j < count_j) { CkJsonObject_putJ(jResp,j); j = j + 1; } j = 0; count_j = CkJsonObject_SizeOfArray(jResp,"Questions[i].ColumnNames"); while (j < count_j) { CkJsonObject_putJ(jResp,j); j = j + 1; } i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"ConsentForms"); while (i < count_i) { CkJsonObject_putI(jResp,i); Id = CkJsonObject_stringOf(jResp,"ConsentForms[i].Id"); Name = CkJsonObject_stringOf(jResp,"ConsentForms[i].Name"); DocumentType = CkJsonObject_stringOf(jResp,"ConsentForms[i].DocumentType"); Signed = CkJsonObject_BoolOf(jResp,"ConsentForms[i].Signed"); DateSubmitted = CkJsonObject_IntOf(jResp,"ConsentForms[i].DateSubmitted"); i = i + 1; } CkHttp_Dispose(http); CkJsonObject_Dispose(json); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.