Java 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:

Java Example

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://api.stripe.com/v1/events/evt_1BnETJGswQrCoh0XAl7jSmFB
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(rest.lastErrorText());
        return;
        }

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

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestNoBodySb("GET","/v1/events/evt_1BnETJGswQrCoh0XAl7jSmFB",sbResponseBody);
    if (success != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.LoadSb(sbResponseBody);

    String id;
    String object;
    boolean api_version;
    int created;
    String dataObjectId;
    String dataObjectObject;
    int dataObjectAmount;
    int dataObjectCreated;
    String dataObjectCurrency;
    String dataObjectInterval;
    int dataObjectInterval_count;
    boolean dataObjectLivemode;
    String dataObjectName;
    boolean dataObjectStatement_descriptor;
    boolean dataObjectTrial_period_days;
    boolean livemode;
    int pending_webhooks;
    boolean requestId;
    boolean requestIdempotency_key;
    String type;

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