Stripe Integration

Hi,

I want examples of workflows for the integration of stripe Invoice/InvoiceItems. Stripe Api

My Workflow:

The output of my function, from which I want to insert

[
{
"currency": "USD",
"customer": "cus_LHyuMeu7k1uijM",
"lines": [
{
"object": "list",
"data": [
{
"object": "line_item",
"amount": 1072.5,
"currency": "USD",
"description": null,
"metadata": {
"SF_ID": "a0K3J000000BJbfUAG"
},
"price": {
"object": "price",
"currency": "USD",
"metadata": {
"SF_ID": ""
},
"product": "prod_LIS1Qmmneqrj7u",
"unit_amount": "",
"unit_amount_decimal": ""
},
"quantity": 10,
"subscription": null,
"type": "invoiceitem"
}
]
},
{
"object": "list",
"data": [
{
"object": "line_item",
"amount": 3000,
"currency": "USD",
"description": null,
"metadata": {
"SF_ID": "a0K3J000000BJbgUAG"
},
"price": {
"object": "price",
"currency": "USD",
"metadata": {
"SF_ID": ""
},
"product": "prod_LIS18uO1163d4O",
"unit_amount": "",
"unit_amount_decimal": ""
},
"quantity": 10,
"subscription": null,
"type": "invoiceitem"
}
]
}
],
"metadata": {
"SF_ID": "a0L3J000002WfMHUA0"
}
}
]


Can someone help me Please?

Hi @jan , @MutedJam Can you help me please? I am a beginner and I am really stuck :pray:

I am sorry, we can sadly not all work 7 days a week. For that reason will often more complicated custom requests have to wait till Monday.

1 Like

Hey @Hasnaa_SOUIBA, I had a look into your request but I am not sure I fully understand it. With what exactly are you having trouble? Do you want to send the full output from your Function node to https://api.stripe.com/v1/invoices using the HTTP Request node or just the item itself (not the array)?

If it’s just the JSON payload you are generating in your Function node, you could set the Body Content Type option of your HTTP Request node to JSON:
image

Then, in the Body Parameters field, use an expression of {{$json}} representing the entire JSON item.

Hey @MutedJam Thank you for agreeing to help me.

I want to send the full output from my Function node to https://api.stripe.com/v1/invoices using the Same HTTP Request node.

the output of my function contains two elements:

1/ https://stripe.com/docs/api/invoices/create?lang=curl
2/ https://stripe.com/docs/api/invoiceitems/create?lang=curl


I tried to insert them separately

Worflow

The invoice is created on stripe but I still have an error that I don’t understand

Error
[
  {
    "id": "in_1KdE4wJPtxHU7P0SatgYor4z",
    "object": "invoice",
    "account_country": "FR",
    "account_name": "SOUIBA",
    "account_tax_ids": null,
    "amount_due": 990,
    "amount_paid": 0,
    "amount_remaining": 990,
    "application_fee_amount": null,
    "attempt_count": 0,
    "attempted": false,
    "auto_advance": false,
    "automatic_tax": {
      "enabled": false,
      "status": null
    },
    "billing_reason": "manual",
    "charge": null,
    "collection_method": "charge_automatically",
    "created": 1647265014,
    "currency": "usd",
    "custom_fields": null,
    "customer": "cus_LHyuMeu7k1uijM",
    "customer_address": {
      "city": " Villefranche-sur-SaĂ´ne",
      "country": "France",
      "line1": "300 Rue Alexandre Richetta",
      "line2": "",
      "postal_code": " 69400",
      "state": "Auvergne Rhone Alpes"
    },
    "customer_email": null,
    "customer_name": "Actipole",
    "customer_phone": null,
    "customer_shipping": null,
    "customer_tax_exempt": "none",
    "customer_tax_ids": [],
    "default_payment_method": null,
    "default_source": null,
    "default_tax_rates": [],
    "description": null,
    "discount": null,
    "discounts": [],
    "due_date": null,
    "ending_balance": null,
    "footer": null,
    "hosted_invoice_url": null,
    "invoice_pdf": null,
    "last_finalization_error": null,
    "lines": {
      "object": "list",
      "data": [
        {
          "id": "il_1KdE4vJPtxHU7P0SQVydDAao",
          "object": "line_item",
          "amount": 990,
          "currency": "usd",
          "description": "GridMate License",
          "discount_amounts": [],
          "discountable": true,
          "discounts": [],
          "invoice_item": "ii_1KdE4vJPtxHU7P0SJX9c1fWV",
          "livemode": false,
          "metadata": {
            "SF_ID": "a0K3J000000BJbfUAG"
          },
          "period": {
            "end": 1647265013,
            "start": 1647265013
          },
          "plan": null,
          "price": {
            "id": "price_1KbrZSJPtxHU7P0SZd7Clz3P",
            "object": "price",
            "active": true,
            "billing_scheme": "per_unit",
            "created": 1646940166,
            "currency": "usd",
            "livemode": false,
            "lookup_key": null,
            "metadata": {
              "SF_ID": "01u3i000007vMR5AAM",
              "Pricebook2Id": "01s3i000002R0xTAAS"
            },
            "nickname": null,
            "product": "prod_LIS1Qmmneqrj7u",
            "recurring": null,
            "tax_behavior": "unspecified",
            "tiers_mode": null,
            "transform_quantity": null,
            "type": "one_time",
            "unit_amount": 99,
            "unit_amount_decimal": "99"
          },
          "proration": false,
          "proration_details": {
            "credited_items": null
          },
          "quantity": 10,
          "subscription": null,
          "tax_amounts": [],
          "tax_rates": [],
          "type": "invoiceitem"
        },
        {
          "id": "il_1KdE4vJPtxHU7P0S47uYMt5A",
          "object": "line_item",
          "amount": 0,
          "currency": "usd",
          "description": "Non Profit License",
          "discount_amounts": [],
          "discountable": true,
          "discounts": [],
          "invoice_item": "ii_1KdE4vJPtxHU7P0SLMnpIFMv",
          "livemode": false,
          "metadata": {
            "SF_ID": "a0K3J000000BJbgUAG"
          },
          "period": {
            "end": 1647265013,
            "start": 1647265013
          },
          "plan": null,
          "price": {
            "id": "price_1KbrZSJPtxHU7P0STEIHSxoZ",
            "object": "price",
            "active": true,
            "billing_scheme": "per_unit",
            "created": 1646940166,
            "currency": "usd",
            "livemode": false,
            "lookup_key": null,
            "metadata": {
              "SF_ID": "01u3J000002sud6QAA",
              "Pricebook2Id": "01s3i000002R0xTAAS"
            },
            "nickname": null,
            "product": "prod_LIS18uO1163d4O",
            "recurring": null,
            "tax_behavior": "unspecified",
            "tiers_mode": null,
            "transform_quantity": null,
            "type": "one_time",
            "unit_amount": 0,
            "unit_amount_decimal": "0"
          },
          "proration": false,
          "proration_details": {
            "credited_items": null
          },
          "quantity": 10,
          "subscription": null,
          "tax_amounts": [],
          "tax_rates": [],
          "type": "invoiceitem"
        }
      ],
      "has_more": false,
      "total_count": 2,
      "url": "/v1/invoices/in_1KdE4wJPtxHU7P0SatgYor4z/lines"
    },
    "livemode": false,
    "metadata": {
      "SF_ID": "a0L3J000002WfMHUA0"
    },
    "next_payment_attempt": null,
    "number": null,
    "on_behalf_of": null,
    "paid": false,
    "paid_out_of_band": false,
    "payment_intent": null,
    "payment_settings": {
      "payment_method_options": null,
      "payment_method_types": null
    },
    "period_end": 1647265014,
    "period_start": 1647265014,
    "post_payment_credit_notes_amount": 0,
    "pre_payment_credit_notes_amount": 0,
    "quote": null,
    "receipt_number": null,
    "starting_balance": 0,
    "statement_descriptor": null,
    "status": "draft",
    "status_transitions": {
      "finalized_at": null,
      "marked_uncollectible_at": null,
      "paid_at": null,
      "voided_at": null
    },
    "subscription": null,
    "subtotal": 990,
    "tax": null,
    "test_clock": null,
    "total": 990,
    "total_discount_amounts": [],
    "total_tax_amounts": [],
    "transfer_data": null,
    "webhooks_delivered_at": 1647265014
  },
  {
    "error": {
      "message": "400 - {\"error\":{\"code\":\"parameter_missing\",\"doc_url\":\"https://stripe.com/docs/error-codes/parameter-missing\",\"message\":\"Missing required param: customer.\",\"param\":\"customer\",\"type\":\"invalid_request_error\"}}",
      "name": "Error",
      "stack": "Error: Request failed with status code 400\n    at createError (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/adapters/http.js:269:11)\n    at IncomingMessage.emit (events.js:327:22)\n    at IncomingMessage.EventEmitter.emit (domain.js:467:12)\n    at endReadableNT (internal/streams/readable.js:1327:12)\n    at processTicksAndRejections (internal/process/task_queues.js:80:21)"
    }
  }
]

So the error message coming from Stripe suggests the request doesn’t include all required parameters: Fehlercodes | Stripe-Dokumentation

Do you have the request working successfully (= without the 400 error) outside of n8n (for example in Postman or curl)?

If so, you could send the working request to a page like https://webhook.site/ (make sure to not send your valid credentials or any confidential data), then do the same with n8n and compare the differences to identify what exactly is missing.

@MutedJam It works well on Postman (Status 200)

See capture

I don’t know how to use https://webhook.site/

I was suggesting to simply replace the stripe URL with a URL provided by webhook.site. This would let you inspect the requests sent by both Postman and n8n, making it easier to compare what might be missing here.

It’s done

But on n8n I have two output items: Error + creation of the invoice (and indeed the invoice is created on stripe). So I don’t understand why I have this error

Output - Stripe Invoice
[
{
"error": {
"message": "400 - {"error":{"code":"invoice_no_customer_line_items","doc_url":"https://stripe.com/docs/error-codes/invoice-no-customer-line-items","message":"Nothing to invoice for customer","param":"customer","type":"invalid_request_error"}}",
"name": "Error",
"stack": "Error: Request failed with status code 400 at createError (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/createError.js:16:15) at settle (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/settle.js:17:12) at IncomingMessage.handleStreamEnd (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/adapters/http.js:269:11) at IncomingMessage.emit (events.js:327:22) at IncomingMessage.EventEmitter.emit (domain.js:467:12) at endReadableNT (internal/streams/readable.js:1327:12) at processTicksAndRejections (internal/process/task_queues.js:80:21)"
}
},
{
"id": "in_1KdZpfJPtxHU7P0SxeF5phkR",
"object": "invoice",
"account_country": "FR",
"account_name": "SOUIBA",
"account_tax_ids": null,
"amount_due": 990,
"amount_paid": 0,
"amount_remaining": 990,
"application_fee_amount": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": false,
"automatic_tax": {
"enabled": false,
"status": null
},
"billing_reason": "manual",
"charge": null,
"collection_method": "charge_automatically",
"created": 1647348635,
"currency": "usd",
"custom_fields": null,
"customer": "cus_LHyuMeu7k1uijM",
"customer_address": {
"city": " Villefranche-sur-SaĂ´ne",
"country": "France",
"line1": "300 Rue Alexandre Richetta",
"line2": "",
"postal_code": " 69400",
"state": "Auvergne Rhone Alpes"
},
"customer_email": null,
"customer_name": "Actipole",
"customer_phone": null,
"customer_shipping": null,
"customer_tax_exempt": "none",
"customer_tax_ids": [
],
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [
],
"description": null,
"discount": null,
"discounts": [
],
"due_date": null,
"ending_balance": null,
"footer": null,
"hosted_invoice_url": null,
"invoice_pdf": null,
"last_finalization_error": null,
"lines": {
"object": "list",
"data": [
{
"id": "il_1KdZpfJPtxHU7P0ShktFC9qu",
"object": "line_item",
"amount": 0,
"currency": "usd",
"description": "Non Profit License",
"discount_amounts": [
],
"discountable": true,
"discounts": [
],
"invoice_item": "ii_1KdZpfJPtxHU7P0Szfi6RpJW",
"livemode": false,
"metadata": {
"SF_ID": "a0K3J000000BJbgUAG"
},
"period": {
"end": 1647348635,
"start": 1647348635
},
"plan": null,
"price": {
"id": "price_1KbrZSJPtxHU7P0STEIHSxoZ",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1646940166,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {
"SF_ID": "01u3J000002sud6QAA",
"Pricebook2Id": "01s3i000002R0xTAAS"
},
"nickname": null,
"product": "prod_LIS18uO1163d4O",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 0,
"unit_amount_decimal": "0"
},
"proration": false,
"proration_details": {
"credited_items": null
},
"quantity": 10,
"subscription": null,
"tax_amounts": [
],
"tax_rates": [
],
"type": "invoiceitem"
},
{
"id": "il_1KdZpeJPtxHU7P0SENX6r6kg",
"object": "line_item",
"amount": 990,
"currency": "usd",
"description": "GridMate License",
"discount_amounts": [
],
"discountable": true,
"discounts": [
],
"invoice_item": "ii_1KdZpeJPtxHU7P0SepA4xuzo",
"livemode": false,
"metadata": {
"SF_ID": "a0K3J000000BJbfUAG"
},
"period": {
"end": 1647348634,
"start": 1647348634
},
"plan": null,
"price": {
"id": "price_1KbrZSJPtxHU7P0SZd7Clz3P",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1646940166,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {
"SF_ID": "01u3i000007vMR5AAM",
"Pricebook2Id": "01s3i000002R0xTAAS"
},
"nickname": null,
"product": "prod_LIS1Qmmneqrj7u",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 99,
"unit_amount_decimal": "99"
},
"proration": false,
"proration_details": {
"credited_items": null
},
"quantity": 10,
"subscription": null,
"tax_amounts": [
],
"tax_rates": [
],
"type": "invoiceitem"
}
],
"has_more": false,
"total_count": 2,
"url": "/v1/invoices/in_1KdZpfJPtxHU7P0SxeF5phkR/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"number": null,
"on_behalf_of": null,
"paid": false,
"paid_out_of_band": false,
"payment_intent": null,
"payment_settings": {
"payment_method_options": null,
"payment_method_types": null
},
"period_end": 1647348635,
"period_start": 1647348635,
"post_payment_credit_notes_amount": 0,
"pre_payment_credit_notes_amount": 0,
"quote": null,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "draft",
"status_transitions": {
"finalized_at": null,
"marked_uncollectible_at": null,
"paid_at": null,
"voided_at": null
},
"subscription": null,
"subtotal": 990,
"tax": null,
"test_clock": null,
"total": 990,
"total_discount_amounts": [
],
"total_tax_amounts": [
],
"transfer_data": null,
"webhooks_delivered_at": 1647348635
}
]

Thank you very much for your help @MutedJam !

So what differences are there between the n8n request arriving on webhook.site and your Postman request?

Weebhook.site

customer=cus_LHyuMeu7k1uijM

Postman

{
    "id": "in_1Kda5fJPtxHU7P0S2hpK988b",
    "object": "invoice",
    "account_country": "FR",
    "account_name": "SOUIBA",
    "account_tax_ids": null,
    "amount_due": 990,
    "amount_paid": 0,
    "amount_remaining": 990,
    "application_fee_amount": null,
    "attempt_count": 0,
    "attempted": false,
    "auto_advance": false,
    "automatic_tax": {
        "enabled": false,
        "status": null
    },
    "billing_reason": "manual",
    "charge": null,
    "collection_method": "charge_automatically",
    "created": 1647349627,
    "currency": "usd",
    "custom_fields": null,
    "customer": "cus_LHyuMeu7k1uijM",
    "customer_address": {
        "city": " Villefranche-sur-SaĂ´ne",
        "country": "France",
        "line1": "300 Rue Alexandre Richetta",
        "line2": "",
        "postal_code": " 69400",
        "state": "Auvergne Rhone Alpes"
    },
    "customer_email": null,
    "customer_name": "Actipole",
    "customer_phone": null,
    "customer_shipping": null,
    "customer_tax_exempt": "none",
    "customer_tax_ids": [],
    "default_payment_method": null,
    "default_source": null,
    "default_tax_rates": [],
    "description": null,
    "discount": null,
    "discounts": [],
    "due_date": null,
    "ending_balance": null,
    "footer": null,
    "hosted_invoice_url": null,
    "invoice_pdf": null,
    "last_finalization_error": null,
    "lines": {
        "object": "list",
        "data": [
            {
                "id": "il_1Kda3dJPtxHU7P0SH4MP62RL",
                "object": "line_item",
                "amount": 990,
                "currency": "usd",
                "description": "GridMate License",
                "discount_amounts": [],
                "discountable": true,
                "discounts": [],
                "invoice_item": "ii_1Kda3dJPtxHU7P0SbW9Qe4qu",
                "livemode": false,
                "metadata": {
                    "SF_ID": "a0K3J000000BJbfUAG"
                },
                "period": {
                    "end": 1647349501,
                    "start": 1647349501
                },
                "plan": null,
                "price": {
                    "id": "price_1KbrZSJPtxHU7P0SZd7Clz3P",
                    "object": "price",
                    "active": true,
                    "billing_scheme": "per_unit",
                    "created": 1646940166,
                    "currency": "usd",
                    "livemode": false,
                    "lookup_key": null,
                    "metadata": {
                        "SF_ID": "01u3i000007vMR5AAM",
                        "Pricebook2Id": "01s3i000002R0xTAAS"
                    },
                    "nickname": null,
                    "product": "prod_LIS1Qmmneqrj7u",
                    "recurring": null,
                    "tax_behavior": "unspecified",
                    "tiers_mode": null,
                    "transform_quantity": null,
                    "type": "one_time",
                    "unit_amount": 99,
                    "unit_amount_decimal": "99"
                },
                "proration": false,
                "proration_details": {
                    "credited_items": null
                },
                "quantity": 10,
                "subscription": null,
                "tax_amounts": [],
                "tax_rates": [],
                "type": "invoiceitem"
            },
            {
                "id": "il_1Kda3cJPtxHU7P0Sj2msbPwj",
                "object": "line_item",
                "amount": 0,
                "currency": "usd",
                "description": "Non Profit License",
                "discount_amounts": [],
                "discountable": true,
                "discounts": [],
                "invoice_item": "ii_1Kda3cJPtxHU7P0SSCedz7KQ",
                "livemode": false,
                "metadata": {
                    "SF_ID": "a0K3J000000BJbgUAG"
                },
                "period": {
                    "end": 1647349500,
                    "start": 1647349500
                },
                "plan": null,
                "price": {
                    "id": "price_1KbrZSJPtxHU7P0STEIHSxoZ",
                    "object": "price",
                    "active": true,
                    "billing_scheme": "per_unit",
                    "created": 1646940166,
                    "currency": "usd",
                    "livemode": false,
                    "lookup_key": null,
                    "metadata": {
                        "SF_ID": "01u3J000002sud6QAA",
                        "Pricebook2Id": "01s3i000002R0xTAAS"
                    },
                    "nickname": null,
                    "product": "prod_LIS18uO1163d4O",
                    "recurring": null,
                    "tax_behavior": "unspecified",
                    "tiers_mode": null,
                    "transform_quantity": null,
                    "type": "one_time",
                    "unit_amount": 0,
                    "unit_amount_decimal": "0"
                },
                "proration": false,
                "proration_details": {
                    "credited_items": null
                },
                "quantity": 10,
                "subscription": null,
                "tax_amounts": [],
                "tax_rates": [],
                "type": "invoiceitem"
            }
        ],
        "has_more": false,
        "total_count": 2,
        "url": "/v1/invoices/in_1Kda5fJPtxHU7P0S2hpK988b/lines"
    },
    "livemode": false,
    "metadata": {},
    "next_payment_attempt": null,
    "number": null,
    "on_behalf_of": null,
    "paid": false,
    "paid_out_of_band": false,
    "payment_intent": null,
    "payment_settings": {
        "payment_method_options": null,
        "payment_method_types": null
    },
    "period_end": 1647349627,
    "period_start": 1647349627,
    "post_payment_credit_notes_amount": 0,
    "pre_payment_credit_notes_amount": 0,
    "quote": null,
    "receipt_number": null,
    "starting_balance": 0,
    "statement_descriptor": null,
    "status": "draft",
    "status_transitions": {
        "finalized_at": null,
        "marked_uncollectible_at": null,
        "paid_at": null,
        "voided_at": null
    },
    "subscription": null,
    "subtotal": 990,
    "tax": null,
    "test_clock": null,
    "total": 990,
    "total_discount_amounts": [],
    "total_tax_amounts": [],
    "transfer_data": null,
    "webhooks_delivered_at": 1647349627
}

I am sorry I don’t think I understand what you’re doing here :frowning:

So webhook.site only receives customer=cus_LHyuMeu7k1uijM when you sent the whole example payload using Postman?

And what does it receive when you use n8n for your request?

Just to be clear: The 400 error is coming from Strapi and only they will know what exactly is missing in your request from n8n. Webhook.site is just a possible tool for inspecting and comparing requests. There are probably several other tools like this out there, if you’re more familiar with a similar tool that should also be fine and helpful to use.