At this point, we build the whole JSON in the workflow and use a single dynamic parameter: <body>, but in such a form, I cannot set “allow optional” or “private” attributes for parameters.
You can composte the Array when you call the API by doing :format as text from the list you are loading
Example
Let’s say I when to send an array of user data
The payload should be
Thanks @Jici but your answer is practically my answer:
{ "person": [<List of person>] }
you example is simpler, there is no nested array inside of a user.
The thing is, that with such approach, bubble will identify a single parameter user_list
so you cannot use Allow blank option for name or email
If there is no other option and we need to create the JSON via concatenation (in workflow, not the API connector) then a new error emerges.
Let’s say I have a form with list of people:
Name
Last name
Items - multiple items allowed
that I need to submit to the custom backend in a form for a JSON:
If a user leaves the items or name or lastname empty, then I get a json like this:
I can probably create a calculation to hide empty attributes but imagine you have 50 attributes in a JSON. Each attribute must be have a condition → IF lastname IS EMPTY THEN “” ELSE "lastname": <lastname> That’s a lot of work and a huge mess. That’s why you have the Allow blank checkbox for detected parameters, but I can not use it when JSON I created via concatenation and not inside of API connector’s endpoint.
You’re just not paying attention big dog. You come for help, but you want to be the only one who’s right. And because of that you can’t see the answer right in front of you.
last name is failing because there’s nothing there to empty out the object which would be “” and right now it’s just “lastname”:, but should be “lastname”: “”,
And for this to be setup properly you would want to use format as text.
so your api connector call would just be this line.
{
“person”: [<persons_array>]
}
and when you define what this persons_array variable is going to be, you’ll need to use format as text.
So it might look like Search for persons:format as text
Inside the format as text box will be {“name”:“This persons name”,“lastname”:“This persons lastname”,“items”:[Search for items:format as text]}
and setup the items array just like the persons array
Yes this is complex. Allow blank work only if the API accept empty field (and most of them will accept null, not empty). More than that: number and boolean will mess up if you just activate allow blank in most case
@doug.burden I think I understand the idea, but with a very complex json - dozens of fields, multiple arrays - creating such a calculation is arduous. Every parameter needs to be “wrapped” inside of formatted as text.
I know that JSON fails because the parameter has no value. Adding the parameter only IF IT’S NOT EMPTY would solve the issue, right? But it seems like a messy solution.
I don’t think leaving an empty string is OK. With the PUT method, you clear some existing values on the backend. Also, in the case of a number, a server can reject your request due to a type mismatch.
Sure, got it. Thanks. From what you and @Jici are saying I conclude that there is no better option and we need to create JSON via concatenation with some conditions to avoid empty parameters.
You are right but only if the attribute is a string and not a number. "" means an empty string. You can use 0 but it’s still a value. The only option is null but I’m not sure it will work inside of a bubble calculation.
It will not work if this expect a number or boolean. You need to send null in most case
(“number”:1 … is not like “number”:“1”… like “test”:“null” is not the same thing for “text”:null)