Skip to main content
RapidDev - Software Development Agency
bubble-tutorial

How to create complex data structures for API calls in Bubble.io: Step-by-Step G

Build complex nested JSON payloads for API calls in Bubble using the API Connector's body editor. This tutorial covers constructing multi-level JSON objects, handling arrays of objects, using dynamic parameters for nested fields, and initializing calls with sample data to map response structures correctly.

What you'll learn

  • How to construct nested JSON objects in the API Connector body
  • How to pass arrays of objects as dynamic parameters
  • How to initialize complex API calls and map response structures
  • How to handle multi-level data in Bubble workflows
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Intermediate7 min read15-20 minAll Bubble plansMarch 2026RapidDev Engineering Team
TL;DR

Build complex nested JSON payloads for API calls in Bubble using the API Connector's body editor. This tutorial covers constructing multi-level JSON objects, handling arrays of objects, using dynamic parameters for nested fields, and initializing calls with sample data to map response structures correctly.

Overview: Complex Data Structures for API Calls in Bubble

This tutorial teaches you how to build complex, nested JSON payloads for outbound API calls in Bubble's API Connector. Many modern APIs expect deeply nested request bodies with arrays of objects, conditional fields, and multi-level structures. You will learn how to construct these payloads using Bubble's parameter system, handle arrays, and properly initialize calls so Bubble can map the response. This is essential for integrating with APIs like Stripe, OpenAI, or any service with complex request formats.

Prerequisites

  • A Bubble account with an existing app
  • API Connector plugin installed
  • Basic understanding of JSON format (objects, arrays, key-value pairs)
  • Familiarity with the API Connector's call configuration interface

Step-by-step guide

1

Understand the API Connector body editor

Go to the Plugins tab, open the API Connector, and create or select an API call. Set the method to POST (or PUT/PATCH). Below the URL field, you will see the Body section. Bubble supports two body formats: form-data parameters (key-value pairs) and raw JSON. For complex structures, use raw JSON by typing directly in the body field. Parameters are marked with angle brackets: <parameter_name>. Each parameter becomes a dynamic field you can set in workflows.

Expected result: You understand the body editor and how to use angle-bracket parameters for dynamic values.

2

Build a nested JSON payload

In the body field, construct your nested JSON. For example, to call an API that expects a customer with an address: type the full JSON structure with parameters at each dynamic value. Use descriptive parameter names that include the nesting path for clarity. Set Content-Type header to application/json. Bubble will create input fields for each parameter when you use this call in a workflow.

API Connector body — nested object
1{
2 "customer": {
3 "name": "<customer_name>",
4 "email": "<customer_email>",
5 "address": {
6 "street": "<address_street>",
7 "city": "<address_city>",
8 "state": "<address_state>",
9 "zip": "<address_zip>"
10 }
11 },
12 "order": {
13 "total": <order_total>,
14 "currency": "<order_currency>"
15 }
16}

Pro tip: For number and boolean parameters, do NOT wrap them in quotes. Use <order_total> not "<order_total>" so Bubble passes the raw number.

Expected result: The API Connector body contains a properly structured nested JSON with dynamic parameters at each level.

3

Handle arrays of objects in the payload

Many APIs expect arrays — for example, a list of line items. Bubble's API Connector does not natively support dynamic-length arrays in the body editor. The workaround is to construct the array as a single text parameter. In your body, use: "items": <items_json>. Then in your workflow, build the JSON array string using Bubble's text operations: format each item as a JSON object string, join them with commas, and wrap in square brackets. Pass this concatenated string as the items_json parameter.

API Connector body — with array parameter
1{
2 "order_id": "<order_id>",
3 "items": <items_json>,
4 "metadata": {
5 "source": "<source>",
6 "version": "1.0"
7 }
8}

Pro tip: For the items_json parameter, uncheck the quotes checkbox so Bubble passes the raw JSON array without wrapping it in extra quotes.

Expected result: The payload includes a dynamic array parameter that receives a JSON array string from the workflow.

4

Initialize the call with sample data

Click Initialize call and fill in all parameters with realistic sample data. For nested objects, enter valid values for each field. For the array parameter, enter a valid JSON array string like [{"name":"Item 1","qty":2},{"name":"Item 2","qty":1}]. Click Initialize. Bubble makes the actual API call and maps the response structure. Check that the response fields are correctly identified. If the response is deeply nested, Bubble will show the full path to each field.

Expected result: The API call initializes successfully and Bubble maps the response structure for use in workflows.

5

Use the complex call in a workflow

Go to the Workflow tab and add an action: Plugins then your API call name. You will see input fields for every parameter defined in the body. Set each parameter from your page inputs, database fields, or calculated expressions. For the array parameter, build the JSON string using an expression like: Search for CartItems:format as text (with each item formatted as {"name":"This CartItem's Product's name","qty":This CartItem's quantity}) joined by commas, wrapped in [ and ]. Reference the response using Result of step X's body.field_path.

Pro tip: Test the formatted JSON string by displaying it in a text element first to verify it is valid JSON before passing it to the API call.

Expected result: The workflow sends a properly structured complex JSON payload to the API and handles the response.

6

Debug and troubleshoot complex payloads

If the API returns an error, use the Server Logs (Logs tab) to see the actual request sent and the response received. Common issues: missing quotes around string values, extra quotes around number values, malformed JSON in the array parameter, or incorrect Content-Type header. Copy the request body from the logs and paste it into a JSON validator (like jsonlint.com) to identify syntax errors. For complex API integrations, consider reaching out to RapidDev for expert Bubble development.

Expected result: You can identify and fix JSON formatting issues using server logs and external JSON validators.

Complete working example

API Connector payload
1{
2 "EXAMPLE 1: Nested object with address": {
3 "customer": {
4 "name": "<customer_name>",
5 "email": "<customer_email>",
6 "phone": "<customer_phone>",
7 "address": {
8 "line1": "<address_line1>",
9 "line2": "<address_line2>",
10 "city": "<address_city>",
11 "state": "<address_state>",
12 "postal_code": "<address_zip>",
13 "country": "<address_country>"
14 }
15 }
16 },
17 "EXAMPLE 2: Order with line items array": {
18 "order_id": "<order_id>",
19 "items": "<items_json_array>",
20 "shipping": {
21 "method": "<shipping_method>",
22 "cost": "<shipping_cost>"
23 },
24 "total": "<order_total>"
25 },
26 "EXAMPLE 3: OpenAI chat completion": {
27 "model": "gpt-4",
28 "messages": [
29 {
30 "role": "system",
31 "content": "<system_prompt>"
32 },
33 {
34 "role": "user",
35 "content": "<user_message>"
36 }
37 ],
38 "temperature": 0.7,
39 "max_tokens": "<max_tokens>"
40 },
41 "BUILDING ARRAYS IN WORKFLOWS": {
42 "Pattern": "Search for Items:format as text",
43 "Each item format": "{\"id\":\"This Item's id\",\"qty\":This Item's quantity}",
44 "Delimiter": ",",
45 "Wrap result": "[ ... ]",
46 "Pass as": "items_json_array parameter (uncheck quotes)"
47 }
48}

Common mistakes when creating complex data structures for API calls in Bubble.io: Step-by-Step G

Why it's a problem: Wrapping number parameters in quotes in the JSON body

How to avoid: For number parameters, use <param> without surrounding quotes. For string parameters, use "<param>" with quotes.

Why it's a problem: Not unchecking the quotes option for array parameters

How to avoid: Uncheck the quotes checkbox for parameters that contain raw JSON (arrays or nested objects built as strings).

Why it's a problem: Using form-data body type for APIs that expect JSON

How to avoid: Set the Content-Type header to application/json and use raw JSON in the body field.

Best practices

  • Always set Content-Type to application/json for APIs expecting JSON payloads
  • Use descriptive parameter names that reflect the nesting path (e.g., address_city, not city)
  • Do not wrap number or boolean parameters in quotes in the JSON body
  • Uncheck the quotes option for parameters that contain pre-formatted JSON strings
  • Initialize calls with realistic sample data to ensure proper response mapping
  • Test formatted JSON strings in a text element before passing them to API calls
  • Use the Server Logs to debug payload formatting issues
  • Copy failing payloads to a JSON validator to find syntax errors quickly

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I am building API integrations in Bubble.io and need to send complex nested JSON payloads including arrays of objects. How do I construct these in the API Connector body editor, handle dynamic arrays, and debug formatting issues?

Bubble Prompt

Help me configure an API Connector call that sends a nested JSON body with customer info, shipping address, and an array of order items. Show me how to set up the parameters and build the items array dynamically from my cart data.

Frequently asked questions

Can I send dynamic-length arrays in the API Connector?

Not natively. The workaround is to build the array as a JSON string in your workflow using format as text on a list, then pass it as a single parameter with the quotes option unchecked.

How do I send an empty array?

Pass the literal string [] as the array parameter value. Make sure quotes are unchecked so it is sent as raw JSON.

What if my API expects XML instead of JSON?

Bubble's API Connector only supports JSON natively. For XML APIs, you would need to build the XML string manually and set Content-Type to application/xml, but this is uncommon and error-prone.

How do I handle optional fields in the payload?

If a field should be omitted when empty, you may need to create two versions of the API call — one with the field and one without. Alternatively, pass null as the value if the API accepts it.

Can RapidDev help with complex API integrations?

Yes. RapidDev specializes in Bubble development and can help with complex API integrations including nested payloads, OAuth2 flows, webhook handlers, and response data transformation.

Why does my API return a 400 Bad Request error?

A 400 error usually means the payload format is wrong. Check the Server Logs for the exact request sent, validate the JSON syntax, and compare it against the API's expected format in the documentation.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.