AutoIt Requires Chilkat v11.7.0+
AutoIt
Stripe: Draft an invoice and attach line items
See more Stripe Examples
Create a draft for a customer and attach a priced line item to that specific invoice.
Stripe documentation and cURL example
Chilkat AutoIt Downloads
Local $bSuccess = False
; Requires an unlocked Chilkat bundle. See Global Unlock Sample.
; Supply a restricted sandbox key from merchant-controlled configuration.
Local $sApiKey = "YOUR_STRIPE_TEST_KEY"
; Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
Local $sOperationId = "YOUR_SAVED_OPERATION_UUID"
$oCurl = ObjCreate("Chilkat.HttpCurl")
$oCmd = ObjCreate("Chilkat.StringBuilder")
$oJson = ObjCreate("Chilkat.JsonObject")
Local $iReplaced
Local $sCustomerId = "cus_FROM_BILLING_ACCOUNT"
Local $sPriceId = "price_FROM_CATALOG"
; curl -X POST "https://api.stripe.com/v1/invoices" \
; -u "$STRIPE_API_KEY:" \
; -H "Stripe-Version: 2026-10-28.endive" \
; -H "Idempotency-Key: {operationId}-draft" \
; -d "customer={customerId}" \
; -d "collection_method=send_invoice" \
; -d "days_until_due=30" \
; -d "auto_advance=false" \
; -d "pending_invoice_items_behavior=exclude"
$oCmd.SetString("curl -X POST ""https://api.stripe.com/v1/invoices""")
$oCmd.Append(" -u ""@KEY@:""")
$oCmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
$oCmd.Append(" -H ""Idempotency-Key: @OP@-draft""")
$oCmd.Append(" -d ""customer=@CUSTOMER@""")
$oCmd.Append(" -d ""collection_method=send_invoice""")
$oCmd.Append(" -d ""days_until_due=30""")
$oCmd.Append(" -d ""auto_advance=false""")
$oCmd.Append(" -d ""pending_invoice_items_behavior=exclude""")
$iReplaced = $oCmd.Replace("@CUSTOMER@",$sCustomerId)
$iReplaced = $oCmd.Replace("@OP@",$sOperationId)
$iReplaced = $oCmd.Replace("@KEY@",$sApiKey)
$bSuccess = $oCurl.DoYourThing($oCmd.GetAsString())
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response. Chilkat failure code: " & $oCurl.FailReason & @CRLF)
Exit
EndIf
$bSuccess = $oCurl.GetResponseJson($oJson)
If (($oCurl.StatusCode <> 200) Or ($bSuccess <> True)) Then
ConsoleWrite("Stripe HTTP " & $oCurl.StatusCode & " Request-Id: " & $oCurl.GetResponseHeaderField("Request-Id") & @CRLF)
If ($bSuccess = True) Then
ConsoleWrite($oJson.StringOf("error.message") & @CRLF)
EndIf
Exit
EndIf
Local $sInvoiceId = $oJson.StringOf("id")
ConsoleWrite("Save draft invoice ID: " & $sInvoiceId & @CRLF)
; Attach this line to the draft. Use a distinct stable key per local line on retries.
; curl -X POST "https://api.stripe.com/v1/invoiceitems" \
; -u "$STRIPE_API_KEY:" \
; -H "Stripe-Version: 2026-10-28.endive" \
; -H "Idempotency-Key: {operationId}-line-1" \
; -d "invoice={invoiceId}" \
; -d "customer={customerId}" \
; -d "pricing[price]={priceId}" \
; -d "quantity=2"
$oCmd.SetString("curl -X POST ""https://api.stripe.com/v1/invoiceitems""")
$oCmd.Append(" -u ""@KEY@:""")
$oCmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
$oCmd.Append(" -H ""Idempotency-Key: @OP@-line-1""")
$oCmd.Append(" -d ""invoice=@INVOICE@""")
$oCmd.Append(" -d ""customer=@CUSTOMER@""")
$oCmd.Append(" -d ""pricing[price]=@PRICE@""")
$oCmd.Append(" -d ""quantity=2""")
$iReplaced = $oCmd.Replace("@INVOICE@",$sInvoiceId)
$iReplaced = $oCmd.Replace("@CUSTOMER@",$sCustomerId)
$iReplaced = $oCmd.Replace("@PRICE@",$sPriceId)
$iReplaced = $oCmd.Replace("@OP@",$sOperationId)
$iReplaced = $oCmd.Replace("@KEY@",$sApiKey)
$bSuccess = $oCurl.DoYourThing($oCmd.GetAsString())
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response. Chilkat failure code: " & $oCurl.FailReason & @CRLF)
Exit
EndIf
$bSuccess = $oCurl.GetResponseJson($oJson)
If (($oCurl.StatusCode <> 200) Or ($bSuccess <> True)) Then
ConsoleWrite("Stripe HTTP " & $oCurl.StatusCode & " Request-Id: " & $oCurl.GetResponseHeaderField("Request-Id") & @CRLF)
If ($bSuccess = True) Then
ConsoleWrite($oJson.StringOf("error.message") & @CRLF)
EndIf
Exit
EndIf
ConsoleWrite("invoice = " & $oJson.StringOf("invoice") & @CRLF)
ConsoleWrite("id = " & $oJson.StringOf("id") & @CRLF)
ConsoleWrite("amount = " & $oJson.StringOf("amount") & @CRLF)
ConsoleWrite("currency = " & $oJson.StringOf("currency") & @CRLF)