Rest API Response body in Rest client(like postman, restclient)

-1
Hi, I have created a GET Rest API using RestService Module in Mendix and I am trying to call this API from POSTMAN. I have used seriliazeObjectToJson from RestService Module but response is  not coming into Body. I have attached a screenshot for the microflow. I am trying to get a list of users which will have username and password in it, and want to generate a response  something like below: {       "error": false,       "errorCode": null,       "message": "API call Successfully",       "payload": {             "UserDetails": [{             "username": "xyz",             "password": "qwqewe"         }, {             "username": "ABC",             "password": "poewrw"         }]      } } Any help will be really appreciated.  
asked
1 answers
1

Prakshar,

 

If you go to your url and append "/rest/" it will open a page of all of the rest services that you created. From there you can see what url you have to call in order to trigger the rest service. 

In terms of the response you are trying to get, what you should do is check out the export mapping. You can create an export mapping from a json snippet and configure it to take a parameter. In the microflow you can call that export mapping and it will return a string (which will be your json). To return that string to the user, just set it to be returned on the end event of your microflow. 

 

https://docs.mendix.com/refguide/export-mapping-action

 

EDIT:  To accomplish what you want to do, you need a json structure that has an array of objects. Ill post an example that you can make a slight change to add all the attributes you want to return in your API.

 

First, you need a json structure similar to this. Add as many attributes as you want to export from the accounts table.

 

[{
		"fullname": "name"

	},
	{
		"fullname ": "name"
	},
	{
		"fullname": "name"
	},
	{
		"fullname": "name"
	}
]

 


Make sure all elements are selected in the export mapping and click map automatically. It should generate a domain model similar to this

 

in your API microflow, add something similar to this

 

https://modelshare.mendix.com/models/2fefd6bd-117c-413f-be25-4cef5d293227/exporting-account-data

 

you will retrieve accounts. Create one object of root. Iterate the accounts list and create objects of json object with all the values set that you want to return, as well ass associating to the new root object. Then you can call the export mapping activity and pass the root object to return your json string. 

 

Hope this helps.

answered