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

DataFlex Example

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJsonResponse
    String sObject
    String sUrl
    Boolean iHas_more
    Integer i
    Integer iCount_i
    String sId
    Integer iAmount
    String sCurrency
    String sDescription
    Boolean iDiscountable
    Boolean iLivemode
    Integer iPeriodStart
    Integer iPeriodEnd
    Boolean iPlan
    Boolean iProration
    Boolean iQuantity
    Boolean iSubscription
    String sType
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    //  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5
    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "api.stripe.com" iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComSetAuthBasic Of hoRest "STRIPE_SECRET_KEY" "" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestNoBodySb Of hoRest "GET" "/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines?limit=5" vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
    If (Not(IsComObjectCreated(hoJsonResponse))) Begin
        Send CreateComObject of hoJsonResponse
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess

    Get ComStringOf Of hoJsonResponse "object" To sObject
    Get ComStringOf Of hoJsonResponse "url" To sUrl
    Get ComBoolOf Of hoJsonResponse "has_more" To iHas_more
    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Get ComStringOf Of hoJsonResponse "data[i].id" To sId
        Get ComStringOf Of hoJsonResponse "data[i].object" To sObject
        Get ComIntOf Of hoJsonResponse "data[i].amount" To iAmount
        Get ComStringOf Of hoJsonResponse "data[i].currency" To sCurrency
        Get ComStringOf Of hoJsonResponse "data[i].description" To sDescription
        Get ComBoolOf Of hoJsonResponse "data[i].discountable" To iDiscountable
        Get ComBoolOf Of hoJsonResponse "data[i].livemode" To iLivemode
        Get ComIntOf Of hoJsonResponse "data[i].period.start" To iPeriodStart
        Get ComIntOf Of hoJsonResponse "data[i].period.end" To iPeriodEnd
        Get ComIsNullOf Of hoJsonResponse "data[i].plan" To iPlan
        Get ComBoolOf Of hoJsonResponse "data[i].proration" To iProration
        Get ComIsNullOf Of hoJsonResponse "data[i].quantity" To iQuantity
        Get ComIsNullOf Of hoJsonResponse "data[i].subscription" To iSubscription
        Get ComStringOf Of hoJsonResponse "data[i].type" To sType
        Move i + 1 To i
    Loop



End_Procedure

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"
    }
  ]
}