API Form POST, sending information in a repeat form as a JSON Blob, list element

@ben @Teodor or to anyone in the community with experience working with JSON.

For the most part I have created a very user friendly multi-step form that is using the API form as well as repeat form elements. @kfawcett has been very kind to take time out of his day to help me when I got stuck so Props to him!

However, I am now at the point where I need to pass the data to our REST API from the repeat form and the data as it is saved in the Variable does not place the data to our system in a way that it accepts it. I am told that it is looking for either a list of objects placed under an object, or as a JSON Blob.

The below code is the formate for the POST pulled directly from our SWAGGER doc. The issues I am having are with the “AirTravel” “Vehicles”, and “OtherResidences”.

{
  "NumberIndividualsInHousehold": 0,
  "NumberAutosForHousehold": 0,
  "AirTravel": [{"AirFlightCategory":"ShortHaul","AirHrsOnCommercialFlights": 3.0, "AirNumberOfSegments": 2, "AirTripMultiplier": 2, "AirPeriodOfReferencePerWkMoYr":"PerYr"},
          {"AirCategoryID":"1","AirHrsOnCommercialFlights": 16.0, "AirNumberOfSegments": 2}],
  "OverallAirHrsOnCommercialFlights": 0,
  "OverallAirNumberOfSegments": 0,
  "OverallAirRefPeriodWkMoYr": "string",
  "Vehicles": [{"VehManufacturer": "Toyota", "VehYear": "2018", "VehMilesPerGallon": 32.5, "VehMilesDrivenPerYear": 18000.0 , "VehPctCityDriving": 80.0},
           {"VehManufacturer": "Ford", "VehYear": "2020", "VehMilesPerGallon": 30.0, "VehMilesDrivenPerYear": 22000.0 , "VehPctCityDriving": 20.0}],
  "OverallVehMilesDrivenPerYear": 0,
  "OverallVehMilesPerGallon": 0,
  "NoRegularVehicleAutoMaintenance": true,
  "OtherResidences": [{"ResidentialHouseLable": "SummerHome","ResidentialZipCode": "85207", "ResidentialNatGasTherms": 1.25,
"ResidentialElectKilowattHours": 100.0, "ResidentialElectOffsetPct": 0.34},
{"ResidentialHouseLable": "MomsHouse", "ResidentialZipCode": "85207","ResidentialNatGasTherms": 1.5,
"ResidentialElectKilowattHours": 250.5, "ResidentialElectOffsetPct": 0.5}],
  "PrincipalResZipCode": "85205",
  "PrincipalResNatGasBill": 0,
  "PrincipalResNatGasThousandCubicFeet": 0,
  "PrincipalResNatGasTherms": 0,
  "PrincipalResElectBill": 150.0,
  "PrincipalResElectKilowattHours": 450.5,
  "PrincipalResElectOffsetPct": 0.25,
  "PrincipalResFuelOilBill": 0,
  "PrincipalResFuelOilGallons": 0,
  "PrincipalResPropaneBill": 0,
  "PrincipalResPropaneGallons": 0
}   

These two images show how the data is stored in the variable. As you can see the variable is not just storing the data inputted by the user but all of the data associated with the input.

![Screenshot 2023-03-07 at 3.19.15 PM|690x495]

(upload://vZD0iRt9VW9e4Rc8NE9nyKCyAY1.png)

This is just a small segment of this info it captures. What I am looking for is only the input data associated with the ID.

So digging a little deeper using the dmx.app.data. I was able to show the following payload data;

and Header data;

Finally, below is a small section of code first the API form;

            <form id="carbonCalculator" is="dmx-api-form" method="post" action="https://staging.gecapi.com:3500/calc_carbon" post-data="json" dmx-header:key="key.value">

Second from the repeat form section AirTravel (the others are just too long;

                        <legend class="col-form-label">Now a little about your family travel</legend>
                    <div is="dmx-form-repeat" id="AirTravel" dmx-bind:items="1">
                        <div class="row align-items-center justify-content-center">
                            <div class="d-flex justify-content-center align-items-center">
                                <div class="col-5 cal2">
                                    <div class="form-group md-3">
                                        <div class="col cal2 align-self-center d-flex flex-column align-items-start">

                                            <label for="electricUpload" class="form-label">What is the classification of this flight type?</label><select id="flightType" class="form-select">
                                                <option value="1">Personal</option>
                                                <option value="2">Business</option>
                                            </select>
                                        </div>
                                        <div class="col cal2 align-self-center d-flex flex-column align-items-start">

                                            <label for="electricUpload" class="form-label">What type of flight duration?</label><select id="AirFlightCategory" class="form-select">
                                                <option value="Short Haul">Short Haul</option>
                                                <option value="Medium Haul">Medium Haul</option>
                                                <option value="Long Haul">Long Haul</option>
                                            </select>
                                        </div>
                                        <div class="col cal2 align-self-center d-flex flex-column align-items-start">
                                            <label for="electricUpload" class="form-label">Average amount of hours on flight?</label>
                                            <input type="text" class="form-control" id="AirHrsOnCommercialFlights" name="AirHrsOnCommercialFlights" aria-describedby="input2_help" placeholder="Estimated Hours">
                                        </div>
                                        <div class="col cal2 align-self-center d-flex flex-column align-items-start">
                                            <label for="electricUpload" class="form-label">How many passengers?</label>
                                            <input type="text" class="form-control" id="AirTripMultiplier" name="AirTripMultiplier" aria-describedby="input2_help" placeholder="Passenger Number">
                                        </div>
                                        <div class="col cal2 align-self-center d-flex flex-column align-items-start">
                                            <label for="electricUpload" class="form-label">How many takeoffs?</label>
                                            <input type="text" class="form-control" id="AirNumberOfSegments" name="AirNumberOfSegments" aria-describedby="input2_help" placeholder="Number of Takeoffs ">
                                        </div>
                                        <div class="col cal2 d-flex justify-content-between">
                                            <button id="btn12" class="btn btn-primary btn-sm" dmx-on:click="AirTravel.add()">Add Flight</button>
                                            <button id="btn13" class="btn btn-danger btn-sm" dmx-on:click="AirTravel.remove($index)">Remove</button>
                                        </div>
                                    </div>
                                    <div class="d-flex justify-content-between">
                                        <button id="btn14" class="btn btn-primary btn-sm" dmx-on:click="calc.setValue(calc.value+1)" dmx-bind:disabled="!flightType.value+!AirFlightCategory.value+!AirHrsOnCommercialFlights.value+!AirTripMultiplier.value+!AirNumberOfSegments.value">Next</button>
                                        <button id="btn15" class="btn btn-success btn-sm" dmx-on:click="calc.setValue(calc.value-1)">Back</button>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>

@Apple any chance you have some insight pertaining to my post? Hope you are doing well my friend.

pinging this again for any support.

Wappler seems to be posting this as JSON as you intend but it still seems to be following PHP/HTML convention for enumerating the arrays instead of JSON’s convention

Sounds like @patrick should take a look and see if this is intended behaviour when the user specifies post-data="json". The user in question is not using Wappler’s back-end, it’s POSTing against another API client-side

How do I get ahold of him? Seems like there is nothing I can do from my end, this is a wrappler issue? I can always have the backend team change the formate to PHP… Would that be a better solution?

@George will assign this topic to Patrick

I’m afraid any solutions without the involvement of the Wappler team might make it more complicated for you

Your backend, in addition to accepting the content-type application/json, could also accept multipart/form-data and in Wappler you’d do a standard API POST without the JSON setting. Would they be able to accept form data and handle it as equivalent to a JSON POST?

Your backend, in addition to accepting the content-type application/json , could also accept multipart/form-data and in Wappler you’d do a standard API POST without the JSON setting. Would they be able to accept form data and handle it as equivalent to a JSON POST?

I think so, I will ask. Could be a simple solution.

Fingers crossed that George assigns it. Thanks again for your help. You doing ok?

It may not make a difference, but why are you storing the data in a variable before sending it to the API form or do you just mean what’s shown in the Request Payload? All of the input fields are already within the form tags, correct?

It’s also possible the AC API form does not work correctly or as intended. A similar issue was encountered today with x-www-form-urlencoded.

I also recently discovered a few other issues with the AC API action.


I guess I am still a nubie but I thought the data needed to be stored in the variable. I am starting to see some limitations here with the Wappler system. I am working with my backend team to see if we can make some changes to our API. just weird that they have issues with these types of calls. Seems like they are more focused on using the Wappler backend than allowing for full API capabilities.

the above is insane!