How do I send data through page form to an API using POST?

0
I have exposed an entity as API. I'm using that API endpoint with POST to add data into that entity.  How do I send that body of data in the REST SERVICE?
asked
2 answers
1

I just wondering, why do you need a post api to send data from a page to the database?

Are you talking about a page in Mendix or from a different source?

Incase of mendix page, try using the save button and skip the api.

In case of a page outside Mendix; the /rest-doc/ handler provide the end point details. And how to implement that on the otherside is a question unrelated to Mendix

answered
0

Hi Priya,

 

https://docs.mendix.com/refguide/integration/consume-a-rest-service/ in this link they have showcased how you can fetch data using a GET call. We use import mappings along with JSON structures for this purpose.

 

For sending data in the body of a POST request, you need to follow the same steps but with the help of an export mapping instead of an import mapping.

 

1. Create a JSON structure with your JSON body.

2. Create an Export Mapping and link in with you JSON structure created in Step 1.

3. In your REST API call Microflow, create the structure of your json body using entities.

For example:

{

   "parent": {

                        "name": "xyz"

                     }

}

 

If this is your request body, then you will create a parent entity and pass in 'xyz' in the name attribute and pass this object to you Call REST activity. 

 

Hope this helps!

answered