Unicode C++ Stripe: List all Events

Back to Index

List events, going back up to 30 days.

Documentation: https://stripe.com/docs/api/curl#list_events

CURL Command

curl https://api.stripe.com/v1/events?limit=3 \
   -u STRIPE_SECRET_KEY: \
   -G

Unicode C++ Example

#include <CkRestW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    CkRestW rest;
    bool success;

    //  URL: https://api.stripe.com/v1/events?limit=3
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect(L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    rest.SetAuthBasic(L"STRIPE_SECRET_KEY",L"");

    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestNoBodySb(L"GET",L"/v1/events?limit=3",sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    CkJsonObjectW jsonResponse;
    jsonResponse.LoadSb(sbResponseBody);

    const wchar_t *object = 0;
    const wchar_t *url = 0;
    bool has_more;
    int i;
    int count_i;
    const wchar_t *id = 0;
    bool api_version;
    int created;
    const wchar_t *dataObjectId = 0;
    const wchar_t *dataObjectObject = 0;
    int dataObjectAmount;
    int dataObjectCreated;
    const wchar_t *dataObjectCurrency = 0;
    const wchar_t *dataObjectInterval = 0;
    int dataObjectInterval_count;
    bool dataObjectLivemode;
    const wchar_t *dataObjectName = 0;
    bool dataObjectStatement_descriptor;
    bool dataObjectTrial_period_days;
    bool livemode;
    int pending_webhooks;
    bool requestId;
    bool requestIdempotency_key;
    const wchar_t *type = 0;

    object = jsonResponse.stringOf(L"object");
    url = jsonResponse.stringOf(L"url");
    has_more = jsonResponse.BoolOf(L"has_more");
    i = 0;
    count_i = jsonResponse.SizeOfArray(L"data");
    while (i < count_i) {
        jsonResponse.put_I(i);
        id = jsonResponse.stringOf(L"data[i].id");
        object = jsonResponse.stringOf(L"data[i].object");
        api_version = jsonResponse.IsNullOf(L"data[i].api_version");
        created = jsonResponse.IntOf(L"data[i].created");
        dataObjectId = jsonResponse.stringOf(L"data[i].data.object.id");
        dataObjectObject = jsonResponse.stringOf(L"data[i].data.object.object");
        dataObjectAmount = jsonResponse.IntOf(L"data[i].data.object.amount");
        dataObjectCreated = jsonResponse.IntOf(L"data[i].data.object.created");
        dataObjectCurrency = jsonResponse.stringOf(L"data[i].data.object.currency");
        dataObjectInterval = jsonResponse.stringOf(L"data[i].data.object.interval");
        dataObjectInterval_count = jsonResponse.IntOf(L"data[i].data.object.interval_count");
        dataObjectLivemode = jsonResponse.BoolOf(L"data[i].data.object.livemode");
        dataObjectName = jsonResponse.stringOf(L"data[i].data.object.name");
        dataObjectStatement_descriptor = jsonResponse.IsNullOf(L"data[i].data.object.statement_descriptor");
        dataObjectTrial_period_days = jsonResponse.IsNullOf(L"data[i].data.object.trial_period_days");
        livemode = jsonResponse.BoolOf(L"data[i].livemode");
        pending_webhooks = jsonResponse.IntOf(L"data[i].pending_webhooks");
        requestId = jsonResponse.IsNullOf(L"data[i].request.id");
        requestIdempotency_key = jsonResponse.IsNullOf(L"data[i].request.idempotency_key");
        type = jsonResponse.stringOf(L"data[i].type");
        i = i + 1;
    }
    }

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/events",
  "has_more": false,
  "data": [
    {
      "id": "evt_1BnETJGswQrCoh0XAl7jSmFB",
      "object": "event",
      "api_version": null,
      "created": 1516662781,
      "data": {
        "object": {
          "id": "gold",
          "object": "plan",
          "amount": 2000,
          "created": 1516662781,
          "currency": "usd",
          "interval": "month",
          "interval_count": 1,
          "livemode": false,
          "metadata": {},
          "name": "T-shirt",
          "statement_descriptor": null,
          "trial_period_days": null
        }
      },
      "livemode": false,
      "pending_webhooks": 0,
      "request": {
        "id": null,
        "idempotency_key": null
      },
      "type": "plan.created"
    }
  ]
}