How can I add custom JSON properties to my PUT request?

0
Hello, In my web app, I am interacting with a REST API. I need to make PUT requests to this API, and to accomplish this, I've created a JSON structure in Mendix with an Import Mapping. The JSON structure looks like this: { "id": "F2A6FC5A-DDBD-4523-B06C-0FA675A3787C", "type": "string", "name": "string", "extrusion": 0, "fence_timeout": 5, "exit_tolerance": 0, "tolerance_timeout": 0, "exit_delay": 100, "radius": 100, "properties": {} }   However, I have to make a PUT request formatted like this: { "id": "F2A6FC5A-DDBD-4523-B06C-0FA675A3787C", "type": "string", "name": "string", "extrusion": 0, "fence_timeout": 5, "exit_tolerance": 0, "tolerance_timeout": 0, "exit_delay": 100, "radius": 100, "properties": { "Damaged": "false", "Battery": "false" } }   Notice that I have added two custom properties to "properties".    I have a microflow with the Call REST Service activity. I’m using a custom request template formatted like this: {{   "id": "{1}",   "type": "{2}",   "name": "{3}",   "extrusion": {4},   "fence_timeout": {5},   "exit_tolerance": {6},   "tolerance_timeout": {7},   "exit_delay": {8},   "radius": {9},   "properties":{{     "Damaged": "{10}",     "Battery": "{11}" }   I have also added these 2 properties as attributes in the relevant entity within the domain model.    In the app, there is a form for users to fill out where they can change the values for these 2 custom properties. Hitting Save executes a microflow which executes the microflow with the Call REST Service.    However, the custom properties are currently not being added after hitting Save.    How can I do this in Mendix?
asked
1 answers
0

Hi Cody,

 

As Ajay suggests, I would also suggest using the Export Mapping functionality in combination with a JSON snippet instead of the Custom Request Template.

 

To verify what exactly is being sent, you can set the log level of REST Consume node to Trace (locally or in the Mendix Cloud), this helps debugging the issue.

 

My suspicion is that the boolean attribute should be without double quotes. In JSON a Boolean is like this:

    "properties": {
        "Damaged": false,
        "Battery": false
    }

 

Something else that catches my attention is the use of capitals (PascalCase) for Damaged and Battery. Are you sure this is correct?

How did you fill the replacement parameters {10} and {11}?

answered