Objective-C Stripe: Retrieve an Invoice's Line Items

Back to Index

Retrieves the line items for a given invoice.

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

CURL Command

curl https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5 \
   -u STRIPE_SECRET_KEY:

Objective-C Example

#import <CkoRest.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

//  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5
BOOL bTls = YES;
int port = 443;
BOOL bAutoReconnect = YES;
success = [rest Connect: @"api.stripe.com" port: [NSNumber numberWithInt: port] tls: bTls autoReconnect: bAutoReconnect];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

[rest SetAuthBasic: @"STRIPE_SECRET_KEY" password: @""];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

CkoJsonObject *jsonResponse = [[CkoJsonObject alloc] init];
[jsonResponse LoadSb: sbResponseBody];

NSString *object = 0;
NSString *url = 0;
BOOL has_more;
int i;
int count_i;
NSString *id = 0;
int amount;
NSString *currency = 0;
NSString *description = 0;
BOOL discountable;
BOOL livemode;
int periodStart;
int periodEnd;
BOOL plan;
BOOL proration;
BOOL quantity;
BOOL subscription;
NSString *type = 0;

object = [jsonResponse StringOf: @"object"];
url = [jsonResponse StringOf: @"url"];
has_more = [jsonResponse BoolOf: @"has_more"];
i = 0;
count_i = [[jsonResponse SizeOfArray: @"data"] intValue];
while (i < count_i) {
    jsonResponse.I = [NSNumber numberWithInt: i];
    id = [jsonResponse StringOf: @"data[i].id"];
    object = [jsonResponse StringOf: @"data[i].object"];
    amount = [[jsonResponse IntOf: @"data[i].amount"] intValue];
    currency = [jsonResponse StringOf: @"data[i].currency"];
    description = [jsonResponse StringOf: @"data[i].description"];
    discountable = [jsonResponse BoolOf: @"data[i].discountable"];
    livemode = [jsonResponse BoolOf: @"data[i].livemode"];
    periodStart = [[jsonResponse IntOf: @"data[i].period.start"] intValue];
    periodEnd = [[jsonResponse IntOf: @"data[i].period.end"] intValue];
    plan = [jsonResponse IsNullOf: @"data[i].plan"];
    proration = [jsonResponse BoolOf: @"data[i].proration"];
    quantity = [jsonResponse IsNullOf: @"data[i].quantity"];
    subscription = [jsonResponse IsNullOf: @"data[i].subscription"];
    type = [jsonResponse StringOf: @"data[i].type"];
    i = i + 1;
}

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines",
  "has_more": false,
  "data": [
    {
      "id": "ii_1BnETLGswQrCoh0XhmXYb8CY",
      "object": "line_item",
      "amount": 1000,
      "currency": "usd",
      "description": "My First Invoice Item (created for API docs)",
      "discountable": true,
      "livemode": false,
      "metadata": {},
      "period": {
        "start": 1516662783,
        "end": 1516662783
      },
      "plan": null,
      "proration": false,
      "quantity": null,
      "subscription": null,
      "type": "invoiceitem"
    }
  ]
}