Sample code for 30+ languages & platforms
C

SMSAPI - Get User Account Information

See more SMSAPI Examples

Get a list of subusers.

Chilkat C Downloads

C
#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonArray.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttp http;
    HCkStringBuilder sbResponseBody;
    HCkJsonArray jarrResp;
    int respStatusCode;
    HCkJsonObject json;
    const char *id;
    const char *username;
    const char *active;
    const char *description;
    const char *from_account;
    const char *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 = CkHttp_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.
    CkHttp_putAuthToken(http,"token_api_oauth");
    CkHttp_SetRequestHeader(http,"Content-Type","application/json");

    sbResponseBody = CkStringBuilder_Create();
    success = CkHttp_QuickGetSb(http,"https://api.smsapi.com/subusers",sbResponseBody);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jarrResp = CkJsonArray_Create();
    CkJsonArray_LoadSb(jarrResp,sbResponseBody);
    CkJsonArray_putEmitCompact(jarrResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonArray_emit(jarrResp));

    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);
        CkJsonArray_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 = CkJsonArray_getSize(jarrResp);
    while (i < count_i) {
        json = CkJsonArray_ObjectAt(jarrResp,i);
        id = CkJsonObject_stringOf(json,"id");
        username = CkJsonObject_stringOf(json,"username");
        active = CkJsonObject_stringOf(json,"active");
        description = CkJsonObject_stringOf(json,"description");
        from_account = CkJsonObject_stringOf(json,"from_account");
        per_month = CkJsonObject_stringOf(json,"per_month");
        CkJsonObject_Dispose(json);
        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonArray_Dispose(jarrResp);

    }