Read Body|| From published Post call

0
Hi All, I am trying to publish a  post api which will have following content in body for user creation-   { "userList": [ { "userName": "user2@gmail.com", "password": "User222@" }, { "userName": "user3@gmail.com", "password": "User322@" } ] } I have created similar Json structure and  respective import and export mappings. But when I am calling this API from postman, Its not reading the body. Actually I am not sure how can I read the content from request body. I am not able to map the body with the created mappings. May be I am missing some steps.   Thanks a million for  any suggestions.
asked
2 answers
3

Hi Prakhar,

 

I think you are using the rest module and using the "Create a microflow as a service". When exposing a post api this way, you can process incoming json by setting up a domain model similar to this.

 

The entities need to be non persistent, and I always start with a top entity called root. Then the next entity down will be the information in the body of the json. The key thing here is that the association name has to match exactly what is in the json. In this case "userList" is the name of the assocation. Next the attribute names need to match exactly as well. Once you have this setup. In your post api microflow you can pass a parameter of "Root" and then retrieve the userlist by retrieving over association. 

 

Here is a blog post that ive used in the past to help me figure this out. 

 

https://www.mendix.com/blog/rest-part-ii-publishing-microflows-rest/

 

hope this helps. Its hard to explain, but let me know if you have any questions. 

 

 

Edit:

 

Here is an example microflow that can help you. Expose this as a rest service and post that json that you showed in your question to the exposed rest service. If you debug the microflow after its triggered by the rest call, you will see that it will be returning the json body data that you are looking for.

https://modelshare.mendix.com/models/782e8c50-1132-49b3-b72d-7b9ec399926c/example-post

 

Also make sure your domain model is setup exactly as I showed originally. It wont work if it is not. The association and attributes need to be named exactly the same. 

answered
0

Hi,

Following is the Json Structure that I am using for this published post call:

 

Import mapping:

Export Mapping:

 

Following is the Microflow that I am trying to publish as POST service :

 

Request Body I have attached at the starting of question.

 

Thank you.

answered