Returns a list of your coupons.
curl https://api.stripe.com/v1/coupons?limit=3 \
-u STRIPE_SECRET_KEY: \
-G
#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 *object;
const char *url;
BOOL has_more;
int i;
int count_i;
const char *id;
BOOL amount_off;
int created;
BOOL currency;
const char *duration;
int duration_in_months;
BOOL livemode;
BOOL max_redemptions;
int percent_off;
BOOL redeem_by;
int times_redeemed;
BOOL valid;
rest = CkRest_Create();
// URL: https://api.stripe.com/v1/coupons?limit=3
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/coupons?limit=3",sbResponseBody);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
jsonResponse = CkJsonObject_Create();
CkJsonObject_LoadSb(jsonResponse,sbResponseBody);
object = CkJsonObject_stringOf(jsonResponse,"object");
url = CkJsonObject_stringOf(jsonResponse,"url");
has_more = CkJsonObject_BoolOf(jsonResponse,"has_more");
i = 0;
count_i = CkJsonObject_SizeOfArray(jsonResponse,"data");
while (i < count_i) {
CkJsonObject_putI(jsonResponse,i);
id = CkJsonObject_stringOf(jsonResponse,"data[i].id");
object = CkJsonObject_stringOf(jsonResponse,"data[i].object");
amount_off = CkJsonObject_IsNullOf(jsonResponse,"data[i].amount_off");
created = CkJsonObject_IntOf(jsonResponse,"data[i].created");
currency = CkJsonObject_IsNullOf(jsonResponse,"data[i].currency");
duration = CkJsonObject_stringOf(jsonResponse,"data[i].duration");
duration_in_months = CkJsonObject_IntOf(jsonResponse,"data[i].duration_in_months");
livemode = CkJsonObject_BoolOf(jsonResponse,"data[i].livemode");
max_redemptions = CkJsonObject_IsNullOf(jsonResponse,"data[i].max_redemptions");
percent_off = CkJsonObject_IntOf(jsonResponse,"data[i].percent_off");
redeem_by = CkJsonObject_IsNullOf(jsonResponse,"data[i].redeem_by");
times_redeemed = CkJsonObject_IntOf(jsonResponse,"data[i].times_redeemed");
valid = CkJsonObject_BoolOf(jsonResponse,"data[i].valid");
i = i + 1;
}
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jsonResponse);
}
{
"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
}
]
}