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:

C Example

#include <C_CkRest.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jsonResponse;
    const char *id;
    const char *object;
    BOOL api_version;
    int created;
    const char *dataObjectId;
    const char *dataObjectObject;
    int dataObjectAmount;
    int dataObjectCreated;
    const char *dataObjectCurrency;
    const char *dataObjectInterval;
    int dataObjectInterval_count;
    BOOL dataObjectLivemode;
    const char *dataObjectName;
    BOOL dataObjectStatement_descriptor;
    BOOL dataObjectTrial_period_days;
    BOOL livemode;
    int pending_webhooks;
    BOOL requestId;
    BOOL requestIdempotency_key;
    const char *type;

    rest = CkRest_Create();

    //  URL: https://api.stripe.com/v1/events/evt_1BnETJGswQrCoh0XAl7jSmFB
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_SetAuthBasic(rest,"STRIPE_SECRET_KEY","");

    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestNoBodySb(rest,"GET","/v1/events/evt_1BnETJGswQrCoh0XAl7jSmFB",sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_LoadSb(jsonResponse,sbResponseBody);

    id = CkJsonObject_stringOf(jsonResponse,"id");
    object = CkJsonObject_stringOf(jsonResponse,"object");
    api_version = CkJsonObject_IsNullOf(jsonResponse,"api_version");
    created = CkJsonObject_IntOf(jsonResponse,"created");
    dataObjectId = CkJsonObject_stringOf(jsonResponse,"data.object.id");
    dataObjectObject = CkJsonObject_stringOf(jsonResponse,"data.object.object");
    dataObjectAmount = CkJsonObject_IntOf(jsonResponse,"data.object.amount");
    dataObjectCreated = CkJsonObject_IntOf(jsonResponse,"data.object.created");
    dataObjectCurrency = CkJsonObject_stringOf(jsonResponse,"data.object.currency");
    dataObjectInterval = CkJsonObject_stringOf(jsonResponse,"data.object.interval");
    dataObjectInterval_count = CkJsonObject_IntOf(jsonResponse,"data.object.interval_count");
    dataObjectLivemode = CkJsonObject_BoolOf(jsonResponse,"data.object.livemode");
    dataObjectName = CkJsonObject_stringOf(jsonResponse,"data.object.name");
    dataObjectStatement_descriptor = CkJsonObject_IsNullOf(jsonResponse,"data.object.statement_descriptor");
    dataObjectTrial_period_days = CkJsonObject_IsNullOf(jsonResponse,"data.object.trial_period_days");
    livemode = CkJsonObject_BoolOf(jsonResponse,"livemode");
    pending_webhooks = CkJsonObject_IntOf(jsonResponse,"pending_webhooks");
    requestId = CkJsonObject_IsNullOf(jsonResponse,"request.id");
    requestIdempotency_key = CkJsonObject_IsNullOf(jsonResponse,"request.idempotency_key");
    type = CkJsonObject_stringOf(jsonResponse,"type");


    CkRest_Dispose(rest);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jsonResponse);

    }

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