Unicode C
Unicode C
SMSAPI - Get User Account Information
See more SMSAPI Examples
Get a list of subusers.Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonArrayW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkStringBuilderW sbResponseBody;
HCkJsonArrayW jarrResp;
int respStatusCode;
HCkJsonObjectW json;
const wchar_t *id;
const wchar_t *username;
const wchar_t *active;
const wchar_t *description;
const wchar_t *from_account;
const wchar_t *per_month;
int i;
int count_i;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Implements the following CURL command:
// curl -i -H "Authorization: Bearer token_api_oauth" \
// -H "Content-Type: application/json" -X GET https://api.smsapi.com/subusers
// 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.
CkHttpW_putAuthToken(http,L"token_api_oauth");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
sbResponseBody = CkStringBuilderW_Create();
success = CkHttpW_QuickGetSb(http,L"https://api.smsapi.com/subusers",sbResponseBody);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
jarrResp = CkJsonArrayW_Create();
CkJsonArrayW_LoadSb(jarrResp,sbResponseBody);
CkJsonArrayW_putEmitCompact(jarrResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonArrayW_emit(jarrResp));
respStatusCode = CkHttpW_getLastStatus(http);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpW_lastHeader(http));
wprintf(L"Failed.\n");
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonArrayW_Dispose(jarrResp);
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// [
// {
// "id": "5A5359173738303F2F95B7E2",
// "username": "subuser1",
// "active": "true",
// "description": "null",
// "from_account": "10.0000",
// "per_month": "0"
// },
// {
// "id": "5A5359173738303F2F95B7E2",
// "username": "subuser2",
// "active": "true",
// "description": "null",
// "from_account": "10.0000",
// "per_month": "0"
// }
// ]
// 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.
i = 0;
count_i = CkJsonArrayW_getSize(jarrResp);
while (i < count_i) {
json = CkJsonArrayW_ObjectAt(jarrResp,i);
id = CkJsonObjectW_stringOf(json,L"id");
username = CkJsonObjectW_stringOf(json,L"username");
active = CkJsonObjectW_stringOf(json,L"active");
description = CkJsonObjectW_stringOf(json,L"description");
from_account = CkJsonObjectW_stringOf(json,L"from_account");
per_month = CkJsonObjectW_stringOf(json,L"per_month");
CkJsonObjectW_Dispose(json);
i = i + 1;
}
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonArrayW_Dispose(jarrResp);
}