Unicode C++ Stripe: Retrieve an Event

Back to Index

Retrieves the details of an event. Supply the unique identifier of the event, which you might have received in a webhook.

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

CURL Command

curl https://api.stripe.com/v1/events/evt_1BnETJGswQrCoh0XAl7jSmFB \
   -u STRIPE_SECRET_KEY:

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/evt_1BnETJGswQrCoh0XAl7jSmFB
    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/evt_1BnETJGswQrCoh0XAl7jSmFB",sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    CkJsonObjectW jsonResponse;
    jsonResponse.LoadSb(sbResponseBody);

    const wchar_t *id = 0;
    const wchar_t *object = 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;

    id = jsonResponse.stringOf(L"id");
    object = jsonResponse.stringOf(L"object");
    api_version = jsonResponse.IsNullOf(L"api_version");
    created = jsonResponse.IntOf(L"created");
    dataObjectId = jsonResponse.stringOf(L"data.object.id");
    dataObjectObject = jsonResponse.stringOf(L"data.object.object");
    dataObjectAmount = jsonResponse.IntOf(L"data.object.amount");
    dataObjectCreated = jsonResponse.IntOf(L"data.object.created");
    dataObjectCurrency = jsonResponse.stringOf(L"data.object.currency");
    dataObjectInterval = jsonResponse.stringOf(L"data.object.interval");
    dataObjectInterval_count = jsonResponse.IntOf(L"data.object.interval_count");
    dataObjectLivemode = jsonResponse.BoolOf(L"data.object.livemode");
    dataObjectName = jsonResponse.stringOf(L"data.object.name");
    dataObjectStatement_descriptor = jsonResponse.IsNullOf(L"data.object.statement_descriptor");
    dataObjectTrial_period_days = jsonResponse.IsNullOf(L"data.object.trial_period_days");
    livemode = jsonResponse.BoolOf(L"livemode");
    pending_webhooks = jsonResponse.IntOf(L"pending_webhooks");
    requestId = jsonResponse.IsNullOf(L"request.id");
    requestIdempotency_key = jsonResponse.IsNullOf(L"request.idempotency_key");
    type = jsonResponse.stringOf(L"type");
    }

Sample JSON Response Body

{
  "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"
}