Unicode C++ Stripe: List all Coupons

Back to Index

Returns a list of your coupons.

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

CURL Command

curl https://api.stripe.com/v1/coupons?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/coupons?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/coupons?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 amount_off;
    int created;
    bool currency;
    const wchar_t *duration = 0;
    int duration_in_months;
    bool livemode;
    bool max_redemptions;
    int percent_off;
    bool redeem_by;
    int times_redeemed;
    bool valid;

    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");
        amount_off = jsonResponse.IsNullOf(L"data[i].amount_off");
        created = jsonResponse.IntOf(L"data[i].created");
        currency = jsonResponse.IsNullOf(L"data[i].currency");
        duration = jsonResponse.stringOf(L"data[i].duration");
        duration_in_months = jsonResponse.IntOf(L"data[i].duration_in_months");
        livemode = jsonResponse.BoolOf(L"data[i].livemode");
        max_redemptions = jsonResponse.IsNullOf(L"data[i].max_redemptions");
        percent_off = jsonResponse.IntOf(L"data[i].percent_off");
        redeem_by = jsonResponse.IsNullOf(L"data[i].redeem_by");
        times_redeemed = jsonResponse.IntOf(L"data[i].times_redeemed");
        valid = jsonResponse.BoolOf(L"data[i].valid");
        i = i + 1;
    }
    }

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/coupons",
  "has_more": false,
  "data": [
    {
      "id": "25OFF",
      "object": "coupon",
      "amount_off": null,
      "created": 1516662783,
      "currency": null,
      "duration": "repeating",
      "duration_in_months": 3,
      "livemode": false,
      "max_redemptions": null,
      "metadata": {},
      "percent_off": 25,
      "redeem_by": null,
      "times_redeemed": 0,
      "valid": true
    }
  ]
}