Passing JSON BODY with Stripe Create Checkout Session for multiple items

Hi everyone,

I’m trying to pass the JSON Body to create a Stripe checkout session for multiple items. I have defined my JSON Body in the API connector:

The problem is when I pass the dynamic data into these dynamic inputs, it keeps returning this error:


I’ve tried to replace the API with Pipe and it called successfully and returned a JSON that I can format successfully. I have tried many ways, remove the /n in the JSON Body, remove the space it still returns the same error.

I’m crazy with this for a few days. Please help!

Example of JSON Body I pass in:

{"custom_fields":[{"key":"firstName","type":"text","label":{"custom":"First Name","type":"custom"}},{"key":"lastName","type":"text","label":{"custom":"Last Name","type":"custom"}}],"metadata":{"KC":2,"KB":2},"line_items":[{"quantity":2,"price":"price_1OrLp5Krc3r80P9jhGoPjWD3"},{"quantity":2,"price":"price_1OrLp5Krc3r80P9jhGoPjWD3"}],"allow_promotion_codes":"true","cancel_url":"https://lyfehealth.us/version-0qvi/?transaction=1712396458917x594358496383467500","payment_intent_data":{"application_fee_amount":142.2,"transfer_data":{"destination":"acct_1NQQ80QOMUKnpu3p"}},"shipping_address_collection":{"allowed_countries":["US"]},"mode":"payment","success_url":"https://lyfehealth.us/version-0qvi/order_confirm?transaction=1712396458917x594358496383467500","shipping_options":[{"shipping_rate":"shr_1NxpIjKrc3r80P9jVym1cX2T"}],"customer":"","customer_email":"gokuxayda123@gmail.com"}```

As explained in the Stripe API docs, the Stripe API doesn’t accept JSON request bodies… only form encoded request bodies.

So you need to format the request body as query parameters

1 Like

If you want to continue to use JSON at first because it’s easier to encode, you can use this plugin to convert the json to something that Stripe accept

1 Like

Is there a way to pass it dynamically? My website has about 10 products at the moment, which means I have to manually create 10 line items like this?

Use the plugin… you could do it dynamicwlly even if this is querystring but adding numbering to array item is very complex. Using the plugin you encode it as json and it will do the numbering for you

But if you search forum, you will find a lot of example on how to set stripe call. This is a very popular subject…

Hey, can you please guide me on how to set the API connector to pass in the result after encoded please?

You do the encoding directly in the plugin not in API connector. The result in the plugin will go in the api connector. I’m on mobile, but will try to post a screenshot later

Thanks, please help me with it, I’ve stuck for a few days

Yes, it can be be dynamic if you put put it as a single string in the body, and put dynamic content between <>. e.g.

mode=payment&success_url=<success_url>&cancel_url=<cancel_url>&<line_items>

For dynamic lines items, just use format as text on your list of line-items, and format each one like:

line_items[0][price_data][currency]=usd&line_items[0][price_data][product_data][name]=myProduct&line_items[0][price_data][unit_amount]=12000&line_items[0][price_data][quantity]=6

&

line_items[1][price_data][currency]=usd&line_items[1][price_data][product_data][name]=myProduct&line_items[1][price_data][unit_amount]=12000&line_items[1][price_data][quantity]=6

&

line_items[2][price_data][currency]=usd&line_items[2][price_data][product_data][name]=myProduct&line_items[2][price_data][unit_amount]=12000&line_items[2][price_data][quantity]=6

Hey @adamhholmes ,

Any clue how to populate the [number] fields without saving each to the database?

Using the plugin mentionned in another post. The plugin will add it for you…