API Node's JSON Body Does Not Support Array Input #5249

Closed
opened 2026-02-21 18:10:04 -05:00 by yindo · 1 comment
Owner

Originally created by @YidaHu on GitHub (Aug 27, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.2

Cloud or Self Hosted

Cloud

Steps to reproduce

In the current implementation of the API node configuration, specifically within the JSON body section, there is a limitation that prevents users from select array types.

  1. In the code execution node, configure an output variable of array type.
  2. In the HTTP node, select the body type as JSON.
  3. Choose the variable.

image

image

✔️ Expected Behavior

The JSON body configuration for API nodes should support select array types, allowing users to construct and send requests that include array structures directly within the JSON body. This enhancement would enable a wider range of API interactions, particularly with services that require array inputs for processing.

Actual Behavior

In the current implementation of the API node configuration, specifically within the JSON body section, there is a limitation that prevents users from select array types. This issue significantly restricts the functionality and flexibility of API requests, as it hinders the ability to send complex data structures, including arrays, to endpoints that expect such formats.

Originally created by @YidaHu on GitHub (Aug 27, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.7.2 ### Cloud or Self Hosted Cloud ### Steps to reproduce In the current implementation of the API node configuration, specifically within the JSON body section, there is a limitation that prevents users from select array types. 1. In the code execution node, configure an output variable of array type. 2. In the HTTP node, select the body type as JSON. 3. Choose the variable. ![image](https://github.com/user-attachments/assets/1b9f4e38-855b-4bc4-8afb-1b4fa94306ba) ![image](https://github.com/user-attachments/assets/ecd7c1f0-efce-4e38-ba14-823d5b07fc16) ### ✔️ Expected Behavior The JSON body configuration for API nodes should support select array types, allowing users to construct and send requests that include array structures directly within the JSON body. This enhancement would enable a wider range of API interactions, particularly with services that require array inputs for processing. ### ❌ Actual Behavior In the current implementation of the API node configuration, specifically within the JSON body section, there is a limitation that prevents users from select array types. This issue significantly restricts the functionality and flexibility of API requests, as it hinders the ability to send complex data structures, including arrays, to endpoints that expect such formats.
yindo added the 💪 enhancement label 2026-02-21 18:10:04 -05:00
yindo closed this issue 2026-02-21 18:10:04 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 27, 2024):

@YidaHu Hello! I'm here to help you with bug fixes, answer questions, and guide you on how to contribute.

The API Node's JSON body configuration does support array input in version 0.7.2. The code includes validation and transformation logic for array types, as shown in the _validate_result and _transform_result methods. Here are the relevant parts of the code:

In the _validate_result method:

if parameter.type.startswith('array'):
    if not isinstance(result.get(parameter.name), list):
        raise ValueError(f"Invalid `array` value for parameter {parameter.name}")
    nested_type = parameter.type[6:-1]
    for item in result.get(parameter.name):
        if nested_type == 'number' and not isinstance(item, int | float):
            raise ValueError(f"Invalid `array[number]` value for parameter {parameter.name}")
        if nested_type == 'string' and not isinstance(item, str):
            raise ValueError(f"Invalid `array[string]` value for parameter {parameter.name}")
        if nested_type == 'object' and not isinstance(item, dict):
            raise ValueError(f"Invalid `array[object]` value for parameter {parameter.name}")

In the _transform_result method:

elif parameter.type.startswith('array'):
    if isinstance(result[parameter.name], list):
        nested_type = parameter.type[6:-1]
        transformed_result[parameter.name] = []
        for item in result[parameter.name]:
            if nested_type == 'number':
                if isinstance(item, int | float):
                    transformed_result[parameter.name].append(item)
                elif isinstance(item, str):
                    try:
                        if '.' in item:
                            transformed_result[parameter.name].append(float(item))
                        else:
                            transformed_result[parameter.name].append(int(item))
                    except ValueError:
                        pass
            elif nested_type == 'string':
                if isinstance(item, str):
                    transformed_result[parameter.name].append(item)
            elif nested_type == 'object':
                if isinstance(item, dict):
                    transformed_result[parameter.name].append(item)

Therefore, the array input is supported in the JSON body configuration for version 0.7.2 [1].

Additionally, there are specific unit tests for the JSON body configuration in API nodes that include array inputs. The tests test__convert_to_http_request_node_for_chatbot and test__convert_to_http_request_node_for_workflow_app both verify the JSON body configuration, including array inputs [2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 27, 2024): <!-- Greeting --> @YidaHu Hello! I'm here to help you with bug fixes, answer questions, and guide you on how to contribute. <!-- Answer --> The API Node's JSON body configuration does support array input in version 0.7.2. The code includes validation and transformation logic for array types, as shown in the `_validate_result` and `_transform_result` methods. Here are the relevant parts of the code: In the `_validate_result` method: ```python if parameter.type.startswith('array'): if not isinstance(result.get(parameter.name), list): raise ValueError(f"Invalid `array` value for parameter {parameter.name}") nested_type = parameter.type[6:-1] for item in result.get(parameter.name): if nested_type == 'number' and not isinstance(item, int | float): raise ValueError(f"Invalid `array[number]` value for parameter {parameter.name}") if nested_type == 'string' and not isinstance(item, str): raise ValueError(f"Invalid `array[string]` value for parameter {parameter.name}") if nested_type == 'object' and not isinstance(item, dict): raise ValueError(f"Invalid `array[object]` value for parameter {parameter.name}") ``` In the `_transform_result` method: ```python elif parameter.type.startswith('array'): if isinstance(result[parameter.name], list): nested_type = parameter.type[6:-1] transformed_result[parameter.name] = [] for item in result[parameter.name]: if nested_type == 'number': if isinstance(item, int | float): transformed_result[parameter.name].append(item) elif isinstance(item, str): try: if '.' in item: transformed_result[parameter.name].append(float(item)) else: transformed_result[parameter.name].append(int(item)) except ValueError: pass elif nested_type == 'string': if isinstance(item, str): transformed_result[parameter.name].append(item) elif nested_type == 'object': if isinstance(item, dict): transformed_result[parameter.name].append(item) ``` Therefore, the array input is supported in the JSON body configuration for version 0.7.2 <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py)</sup>. Additionally, there are specific unit tests for the JSON body configuration in API nodes that include array inputs. The tests `test__convert_to_http_request_node_for_chatbot` and `test__convert_to_http_request_node_for_workflow_app` both verify the JSON body configuration, including array inputs <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/tests/unit_tests/services/workflow/test_workflow_converter.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5249