C# UWP/WinRT 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

C# UWP/WinRT Example

Chilkat.Rest rest = new Chilkat.Rest();
bool success;

//  URL: https://api.stripe.com/v1/coupons?limit=3
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = await rest.ConnectAsync("api.stripe.com",port,bTls,bAutoReconnect);
if (success != true) {
    Debug.WriteLine("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
    Debug.WriteLine(rest.LastErrorText);
    return;
}

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

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
success = await rest.FullRequestNoBodySbAsync("GET","/v1/coupons?limit=3",sbResponseBody);
if (success != true) {
    Debug.WriteLine(rest.LastErrorText);
    return;
}

Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
jsonResponse.LoadSb(sbResponseBody);

string object;
string url;
bool has_more;
int i;
int count_i;
string id;
bool amount_off;
int created;
bool currency;
string duration;
int duration_in_months;
bool livemode;
bool max_redemptions;
int percent_off;
bool redeem_by;
int times_redeemed;
bool valid;

object = jsonResponse.StringOf("object");
url = jsonResponse.StringOf("url");
has_more = jsonResponse.BoolOf("has_more");
i = 0;
count_i = jsonResponse.SizeOfArray("data");
while (i < count_i) {
    jsonResponse.I = i;
    id = jsonResponse.StringOf("data[i].id");
    object = jsonResponse.StringOf("data[i].object");
    amount_off = jsonResponse.IsNullOf("data[i].amount_off");
    created = jsonResponse.IntOf("data[i].created");
    currency = jsonResponse.IsNullOf("data[i].currency");
    duration = jsonResponse.StringOf("data[i].duration");
    duration_in_months = jsonResponse.IntOf("data[i].duration_in_months");
    livemode = jsonResponse.BoolOf("data[i].livemode");
    max_redemptions = jsonResponse.IsNullOf("data[i].max_redemptions");
    percent_off = jsonResponse.IntOf("data[i].percent_off");
    redeem_by = jsonResponse.IsNullOf("data[i].redeem_by");
    times_redeemed = jsonResponse.IntOf("data[i].times_redeemed");
    valid = jsonResponse.BoolOf("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
    }
  ]
}