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) SMSAPI - List ContactsList Contacts For more information, see https://www.smsapi.com/docs?shell#list-contacts
#include <C_CkHttp.h> #include <C_CkStringBuilder.h> #include <C_CkJsonObject.h> #include <C_CkDtObj.h> void ChilkatSample(void) { HCkHttp http; BOOL success; HCkStringBuilder sbResponseBody; HCkJsonObject jResp; int respStatusCode; HCkDtObj date_created; HCkDtObj date_updated; const char *id; const char *first_name; const char *last_name; const char *phone_number; const char *email; const char *gender; const char *city; const char *country; const char *source; int j; int count_j; const char *name; const char *description; const char *created_by; const char *idx; const char *contact_expire_after; const char *contacts_count; int size; 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 -X GET -H "Authorization: Bearer token_api_oauth" https://api.smsapi.com/contacts?phone_number=48500000000 // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code // Adds the "Authorization: Bearer token_api_oauth" header. CkHttp_putAuthToken(http,"token_api_oauth"); sbResponseBody = CkStringBuilder_Create(); success = CkHttp_QuickGetSb(http,"https://api.smsapi.com/contacts?phone_number=48500000000",sbResponseBody); if (success == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); return; } jResp = CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,FALSE); printf("Response Body:\n"); printf("%s\n",CkJsonObject_emit(jResp)); respStatusCode = CkHttp_getLastStatus(http); printf("Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { printf("Response Header:\n"); printf("%s\n",CkHttp_lastHeader(http)); printf("Failed.\n"); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); return; } // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "size": 1, // "collection": [ // { // "id": "5b83ba81a788494a0469490f", // "first_name": "name", // "last_name": "surname", // "phone_number": "48500000000", // "email": "bok@smsapi.com", // "gender": "male", // "city": "City", // "country": "Poland", // "source": "source", // "date_created": "2018-08-27T10:46:57+02:00", // "date_updated": "2018-08-27T10:46:57+02:00", // "groups": [ // { // "id": "59a3ca1fa78849062837cd0c", // "name": "default", // "date_created": "2017-08-28T09:45:35+02:00", // "date_updated": "2017-08-28T09:45:35+02:00", // "description": "", // "created_by": "login", // "idx": null, // "contact_expire_after": null, // "contacts_count": null // } // ] // } // ] // } // 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. date_created = CkDtObj_Create(); date_updated = CkDtObj_Create(); size = CkJsonObject_IntOf(jResp,"size"); i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"collection"); while (i < count_i) { CkJsonObject_putI(jResp,i); id = CkJsonObject_stringOf(jResp,"collection[i].id"); first_name = CkJsonObject_stringOf(jResp,"collection[i].first_name"); last_name = CkJsonObject_stringOf(jResp,"collection[i].last_name"); phone_number = CkJsonObject_stringOf(jResp,"collection[i].phone_number"); email = CkJsonObject_stringOf(jResp,"collection[i].email"); gender = CkJsonObject_stringOf(jResp,"collection[i].gender"); city = CkJsonObject_stringOf(jResp,"collection[i].city"); country = CkJsonObject_stringOf(jResp,"collection[i].country"); source = CkJsonObject_stringOf(jResp,"collection[i].source"); CkJsonObject_DtOf(jResp,"collection[i].date_created",FALSE,date_created); CkJsonObject_DtOf(jResp,"collection[i].date_updated",FALSE,date_updated); j = 0; count_j = CkJsonObject_SizeOfArray(jResp,"collection[i].groups"); while (j < count_j) { CkJsonObject_putJ(jResp,j); id = CkJsonObject_stringOf(jResp,"collection[i].groups[j].id"); name = CkJsonObject_stringOf(jResp,"collection[i].groups[j].name"); CkJsonObject_DtOf(jResp,"collection[i].groups[j].date_created",FALSE,date_created); CkJsonObject_DtOf(jResp,"collection[i].groups[j].date_updated",FALSE,date_updated); description = CkJsonObject_stringOf(jResp,"collection[i].groups[j].description"); created_by = CkJsonObject_stringOf(jResp,"collection[i].groups[j].created_by"); idx = CkJsonObject_stringOf(jResp,"collection[i].groups[j].idx"); contact_expire_after = CkJsonObject_stringOf(jResp,"collection[i].groups[j].contact_expire_after"); contacts_count = CkJsonObject_stringOf(jResp,"collection[i].groups[j].contacts_count"); j = j + 1; } i = i + 1; } CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); CkDtObj_Dispose(date_created); CkDtObj_Dispose(date_updated); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.