Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scalar Values Wrapped as Lists in get_message_body() #28

Open
ronlo04 opened this issue Oct 7, 2024 · 0 comments
Open

Scalar Values Wrapped as Lists in get_message_body() #28

ronlo04 opened this issue Oct 7, 2024 · 0 comments

Comments

@ronlo04
Copy link

ronlo04 commented Oct 7, 2024

I am encountering an issue where scalar values in my request body are being wrapped in lists when using the get_message_body() function from the RAPIClient library. This behavior results in a 400 Bad Request error from the API endpoint, as it expects scalar values but receives lists instead.

The problem seems to stem from how get_message_body() handles the serialization of data. Even when scalar values are provided, they are being converted into lists, which causes issues with the API’s expected input format.

Steps to Reproduce:

Here's a simple demo to reproduce the issue:

# Sample data
data_batch <- list(
  list(
    id = 101,
    name = "Item A",
    quantity = 10,
    price = 5.99,
    description = "Description of Item A"
  ),
  list(
    id = 102,
    name = "Item B",
    quantity = 20,
    price = 3.49,
    description = "Description of Item B"
  )
)


#### Expected Behavior:
The values like `id`, `name`, `quantity`, and `price` should remain as scalar values in the request body. For example:

```json
[
  {
    "id": 101,
    "name": "Item A",
    "quantity": 10,
    "price": 5.99,
    "description": "Description of Item A"
  },
  {
    "id": 102,
    "name": "Item B",
    "quantity": 20,
    "price": 3.49,
    "description": "Description of Item B"
  }
]

Actual Behavior:

The scalar values are being wrapped in lists, resulting in the following incorrect request body:

[
  {
    "id": [101],
    "name": ["Item A"],
    "quantity": [10],
    "price": [5.99],
    "description": ["Description of Item A"]
  },
  {
    "id": [102],
    "name": ["Item B"],
    "quantity": [20],
    "price": [3.49],
    "description": ["Description of Item B"]
  }
]

It seems that the get_message_body() function may be handling scalar values as list. From what I understand, the auto_unbox option could be involved in this behavior, causing scalar values to be unnecessarily wrapped in lists.

Is there a way to ensure that scalar values are not wrapped in lists during the request body preparation? Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant