# Stripe form data API call structure

**URL:** <https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817>\
**Category:** APIs\
**Created:** [July 5, 2024, 3:25pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817 "2024-07-05T15:25:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![alastair1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alastair1/32/227152_2.png) [@alastair1](https://forum.bubble.io/u/alastair1)\
**Post date:** [July 5, 2024, 3:25pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/1 "2024-07-05T15:25:04Z")

</div>

Hi there.

Is anyone able to assist in showing me how to send multiple items to a Stripe checkout session? I have it working with a single item but I don’t know how to handle that there will be a dynamic number of items in each basket.

I haven’t worked with the form data stuff that much but I’m assuming I need to create an array in the workflow but how do I send that given the need to have the [0] for the first item, [1] for the second etc?

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/5/a/5afdf6a5746cc2dc7fc8f3de57ead8aeb5c79294.png)

---

<div class="post-metadata">

**Author:** ![GH5T](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gh5t/32/209141_2.png) [@GH5T](https://forum.bubble.io/u/GH5T)\
**Post date:** [July 5, 2024, 4:48pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/2 "2024-07-05T16:48:27Z")

</div>

Hi. You’ll want to create a loop ideally.

Backend workflows: Create an API workflow, and then at the end of that workflow, “Schedule an API workflow” (the same exact one you just added the workflow to). It will allow you to use “Schedule API workflow on a List” in which you would do that with your list of orders/items.

---

<div class="post-metadata">

**Author:** ![alastair1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alastair1/32/227152_2.png) [@alastair1](https://forum.bubble.io/u/alastair1)\
**Post date:** [July 5, 2024, 5:21pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/3 "2024-07-05T17:21:02Z")

</div>

Sorry, I’m not quite following how that would help in this case. I get the logic of the loop but won’t that just create 10 checkout sessions each with a unique id. I need to send it in a single payload don’t I?

---

<div class="post-metadata">

**Author:** ![GH5T](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gh5t/32/209141_2.png) [@GH5T](https://forum.bubble.io/u/GH5T)\
**Post date:** [July 5, 2024, 5:43pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/4 "2024-07-05T17:43:43Z")

</div>

> [@alastair1](#):
>
> send multiple items to a Stripe checkout session

So according to their [docs](https://docs.stripe.com/billing/subscriptions/multiple-products), I’m not sure you’re using the right parameter.

It looks like `items[0][price]`, `items[0][quantity]`, and so-fourth.

Each item being a subscription, and quantity self-explanitory.

---

<div class="post-metadata">

**Author:** ![alastair1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alastair1/32/227152_2.png) [@alastair1](https://forum.bubble.io/u/alastair1)\
**Post date:** [July 5, 2024, 6:09pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/5 "2024-07-05T18:09:26Z")

</div>

I’m not trying to do a subscription though. I was following the “create session” section here - [https://docs.stripe.com/api/checkout/sessions/create?shell=true&api=true&resource=checkout%20sessions&action=create](https://docs.stripe.com/api/checkout/sessions/create?shell=true&api=true&resource=checkout%20sessions&action=create)

![image001.png](https://us1.discourse-cdn.com/bubble/original/3X/1/7/172b5f94c65e2feff432e672e8cd10232d3f5222.png)

---

<div class="post-metadata">

**Author:** ![GH5T](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gh5t/32/209141_2.png) [@GH5T](https://forum.bubble.io/u/GH5T)\
**Post date:** [July 5, 2024, 6:13pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/6 "2024-07-05T18:13:10Z")

</div>

Same structure as follows.

Each consecutive item you add 1 with the first item always starting with 0 (as the initial index).  
`line_items[0][price]=price_1MotwRLkdIwHu7ixYcPLm5uZ `  
`line_items[0][quantity]=2`  
`line_items[1][price]=price_1MotwRLkdIwHe23D1dszzs133 `  
`line_items[1][quantity]=1`

---

<div class="post-metadata">

**Author:** ![alastair1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alastair1/32/227152_2.png) [@alastair1](https://forum.bubble.io/u/alastair1)\
**Post date:** [July 5, 2024, 6:29pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/7 "2024-07-05T18:29:24Z")

</div>

Ok so I’m following that but I guess my question is that when setting up the API to initialize it, say I create those 4 fields to send as part of the URL encoded call as Stripe doesn’t accept json body.

If the next customer has 3 items how to I create the new field “line\_items[3]” to be able to send the third product? Apologies If I’m being super simple here - appreciate the help!

---

<div class="post-metadata">

**Author:** ![GH5T](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gh5t/32/209141_2.png) [@GH5T](https://forum.bubble.io/u/GH5T)\
**Post date:** [July 5, 2024, 6:40pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/8 "2024-07-05T18:40:15Z")

</div>

Ah. So get rid of everything except “ **success\_url** ”, and “ **mode** ” in your parameters. Your “ **client\_reference\_id** ” should also be a shared and hidden header.

In your BODY:

```auto
{
  line_items: [
    {
      price: 'price_1MotwRLkdIwHu7ixYcPLm5uZ',
      quantity: 2,
    },
  ]
}

```

Now this is the basic structure non-dynamic, right? So, we’ll add the props:

```auto
{
  line_items: [
   <items>
  ]
}

```

Now it will need the same structure as the **object** above, separated by commas. _Each item after will count as the next item._ **Make sure your objects are separated by commas**.

Your “items” parameter should look like this:

```auto
{
  price: 'price_1MotwRLkdIwHu7ixYcPLm5uZ',
  quantity: 2
},
{
  price: 'price_1M433999439Lm5uZ',
  quantity: 1
},
{
  price: 'price_3LkdIw441PLm5uZ',
  quantity: 1
}

```

---

<div class="post-metadata">

**Author:** ![alastair1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alastair1/32/227152_2.png) [@alastair1](https://forum.bubble.io/u/alastair1)\
**Post date:** [July 5, 2024, 6:50pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/9 "2024-07-05T18:50:03Z")

</div>

Thanks for sticking with me…

So I’ve set it up like this:

 ![Screenshot 2024-07-05 194840](https://us1.discourse-cdn.com/bubble/original/3X/6/a/6a30dfc38f409e72432d1b9d93887a3e30d9b744.png)

But I get the following error:

 ![Screenshot 2024-07-05 194830](https://us1.discourse-cdn.com/bubble/original/3X/9/3/93a32a1a26ee37c5c7bb71840641d5514b731160.png)

My understanding was you couldn’t use the json body section with the urlencoded type, but assuming I’m wrong there?

---

<div class="post-metadata">

**Author:** ![GH5T](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gh5t/32/209141_2.png) [@GH5T](https://forum.bubble.io/u/GH5T)\
**Post date:** [July 5, 2024, 6:52pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/10 "2024-07-05T18:52:08Z")

</div>

Change your content-type to “application/json”

Uncheck querystring on both as well. Try that out.

EDIT: Sorry I didn’t notice and scan for all that earlier, I should have re-read what you needed before jumping the gun on a response so quickly.

ALSO: Most of your calls will be application/json so ideally you just make that a shared header as well or it’ll be on each of your calls.

---

<div class="post-metadata">

**Author:** ![alastair1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alastair1/32/227152_2.png) [@alastair1](https://forum.bubble.io/u/alastair1)\
**Post date:** [July 5, 2024, 7:02pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/11 "2024-07-05T19:02:27Z")

</div>

![Screenshot 2024-07-05 200159](https://us1.discourse-cdn.com/bubble/original/3X/7/1/7146058dce75d3e3d5ad10f388bd05f146cdf58e.png)  
All good - appreciate your help. So Stripe docs and the bubble api connector throw an error when I do this.

 ![Screenshot 2024-07-05 200153](https://us1.discourse-cdn.com/bubble/original/3X/4/8/4826429a6ff059c37f3d103becbacbde51d23571.png)

```auto
type or paste code here

```

---

<div class="post-metadata">

**Author:** ![GH5T](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gh5t/32/209141_2.png) [@GH5T](https://forum.bubble.io/u/GH5T)\
**Post date:** [July 5, 2024, 7:07pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/12 "2024-07-05T19:07:31Z")

</div>

Let’s try this as your **items** :

```auto
[{"price":"price_1MotwRLkdIwHu7ixYcPLm5uZ","quantity":2},{"price":"price_1M433999439Lm5uZ","quantity":1},{"price":"price_3LkdIw441PLm5uZ","quantity":1}]

```

Use that array of objects, and your modified body:

```auto
{
  line_items: <items>
}

```

What is did was take the 3 items, and “JSON Minified” them to a single line. Then I wrapped them inside an array bracket “[…]”.

---

<div class="post-metadata">

**Author:** ![alastair1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alastair1/32/227152_2.png) [@alastair1](https://forum.bubble.io/u/alastair1)\
**Post date:** [July 5, 2024, 7:14pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/13 "2024-07-05T19:14:08Z")

</div>

So that didn’t work either - I get an error saying it has to be the form-urlencoded Content-Type. I think I just need to know how to do an array inside the line\_items “Key” section but not sure if that’s possible!

---

<div class="post-metadata">

**Author:** ![GH5T](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gh5t/32/209141_2.png) [@GH5T](https://forum.bubble.io/u/GH5T)\
**Post date:** [July 5, 2024, 7:20pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/14 "2024-07-05T19:20:05Z")

</div>

Yeah, I usually make my own plugin for this reason (I use Node.js as my go to for these scenarios).

Do none of the plugins work for your particular use-case?

> **[Stripe-hosted page](https://docs.stripe.com/checkout/quickstart?client=html)**

This is what I’m referring to, you can easily build that structure if you used the node.js capabilities Bubble has to offer.

In particular, the “server.js” example provided:

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/7/3/73fb76cba3a4227bfe1c8f9381378a1cae27e5c3.png)

It’s not specific for your use-case, but if you used node.js (a server-side action) via a plugin, you could use this:

```auto
const stripe = require('stripe')('

sk_test_51LAgcgEDF3575igK56ppk7HT6R3R6mxVVvr9AtcZqICyP5rJgmZimRG1r4kJ0hDxTgwffRxxCwwxbSsqCD9ZjyoS00xUTAfPfK');
const session = await stripe.checkout.sessions.create({
  success_url: 'https://example.com/success',
  line_items: [
    {
      price: 'price_1MotwRLkdIwHu7ixYcPLm5uZ',
      quantity: 2,
    },
  ],
  mode: 'payment',
});

```

With line items, success\_url, and mode being dynamic properties you provide.

If you want I can guide you over this process to make everything custom for your use-case. Shoot me a DM and we can go over it.

@Jici is the API Connector wizard around here.

---

<div class="post-metadata">

**Author:** ![Jici](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/jici/32/30722_2.png) [@Jici](https://forum.bubble.io/u/Jici)\
**Post date:** [July 5, 2024, 7:39pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/15 "2024-07-05T19:39:11Z")

</div>

This is the plugin you need: [JSON Serialize to URL query Plugin | Bubble](https://bubble.io/plugin/json-serialize-to-url-query-1620746367567x329671693196591100)

Take a json and serialize it to URL that work with Stripe (and other API with similar request)

@Thimo didn’t make a new test page actually. But if we use the @GH5T example, the result will be:  
`line_items[0][price]=price_1MotwRLkdIwHu7ixYcPLm5uZ&line_items[0][quantity]=2&line_items[1][price]=price_1M433999439Lm5uZ&line_items[1][quantity]=1&line_items[2][price]=price_3LkdIw441PLm5uZ&line_items[2][quantity]=1`

From json

```auto
{"line_items": [{"price":"price_1MotwRLkdIwHu7ixYcPLm5uZ","quantity":2},{"price":"price_1M433999439Lm5uZ","quantity":1},{"price":"price_3LkdIw441PLm5uZ","quantity":1}]}

```

It’s very complex with just plain Bubble action. But not impossible (mostly because actually, there’s no “index” of the current item for a list in Bubble function)

---

<div class="post-metadata">

**Author:** ![Jici](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/jici/32/30722_2.png) [@Jici](https://forum.bubble.io/u/Jici)\
**Post date:** [July 5, 2024, 7:44pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/16 "2024-07-05T19:44:02Z")

</div>

BTW, the reason why you got the error for Cannot parsed as JSON, is because you have missing double quotes around line\_items. This is a Bubble error and not API response error (I think it’s a new feature…) However, from what I know, Stripe doesn’t accept json content-type

---

<div class="post-metadata">

**Author:** ![GH5T](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/gh5t/32/209141_2.png) [@GH5T](https://forum.bubble.io/u/GH5T)\
**Post date:** [July 5, 2024, 7:45pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/17 "2024-07-05T19:45:17Z")

</div>

> [@Jici](#):
>
> However, from what I know, Stripe doesn’t accept json content-type

Yeah, I’m just seeing that now (always used node in my use-cases).

> [@Jici](#):
>
> This is the plugin you need: [JSON Serialize to URL query Plugin | Bubble](https://bubble.io/plugin/json-serialize-to-url-query-1620746367567x329671693196591100)

Knew I was missing something! 🙂

---

<div class="post-metadata">

**Author:** ![alastair1](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/alastair1/32/227152_2.png) [@alastair1](https://forum.bubble.io/u/alastair1)\
**Post date:** [July 5, 2024, 8:15pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/18 "2024-07-05T20:15:59Z")

</div>

> [@Jici](#):
>
> t’s very complex with just plain Bubble action. But not impossible (mostly because actually, there’s no “index” of the current item for a list in Bubble function)

Thanks this is great. Just to check - so my thoughts are to have a payment button which:

- Gets the list of products and formats the Json
- Use the plugin to serialize it
- Make the API call with that serialized

However, how do you setup a form-url encoded API call that allows me to pass that dynamic list into it? From what I can see, if I add a Parameter called “line\_items” then have the serialised text it’s not going to work is it?

gets the list of pro

---

<div class="post-metadata">

**Author:** ![Jici](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/jici/32/30722_2.png) [@Jici](https://forum.bubble.io/u/Jici)\
**Post date:** [July 5, 2024, 8:37pm UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/19 "2024-07-05T20:37:21Z")

</div>

If I remember, you have two options  
in url with `?[payload]`  
or with raw data body where you set  
`_*_payload_*_`

---

<div class="post-metadata">

**Author:** ![simon.roge](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@simon.roge](https://forum.bubble.io/u/simon.roge)\
**Post date:** [September 26, 2024, 8:26am UTC](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817/20 "2024-09-26T08:26:20Z")

</div>

Hey Alastair,

I encountered the same problem as you at the beginning. I manage to initialize the call and receive the data. But only in the API Connector.

My initialize call is correct, I have the data displayed.  
key : line\_items  
value : line\_items[0][price]=price\_1Q16iIBG8gDoGKFTHszpB2SN&line\_items[0][quantity]=2&line\_items[1][price]=price\_1Q16ioBG8gDoGKFTt6kpNWO3&line\_items[1][quantity]=10&

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/8/9/89216d313751345feb06183f22b6edc87175ac7b.png)

As soon as I want to make the call in a workflow, it throws me this error.

![image](https://us1.discourse-cdn.com/bubble/original/3X/e/a/ea962e264232670a3391d63cc3bc6c34b10d2502.png)

![image](https://us1.discourse-cdn.com/bubble/original/3X/5/6/5617790daa507a5d334bc7308766475948e9bcdc.png)

Looks like the “querystring” isn’t working.  
Do you have an idea of what I’m doing wrong ?

Thanks in advance,  
Simon

[Next page](https://forum.bubble.io/t/stripe-form-data-api-call-structure/329817.md?page=2)
