Feed Form component with result of REST API call

0
Hi all,   This subject is probably a very common one, but I can't find my way out... This is not a real project but I try to understand how to use the components and configure them before using them in a wider context.   I want to create a basic form containing a component with the list of all countries coming from here: https://restcountries.com/v3.1. Retrieving the list in a microflow is not a problem. But I don't understand how to bind my model to those objects. My microflow creates a list of 'Country' which are not persistable (and I want to keep it non persistable). I'd like to have an entity of my model referencing a Country (by storing some sort of id), and automatically select the right country in the prefilled component.   Does anybody have tip or example that could help?   Regards
asked
2 answers
0

You could use the country enumeration module and then you have all your countries and flags in one go. But to answer your question about consuming REST services. Most of the time REST services have a JSON as result. So you need to create in Mendix first a JSON activity where just copy paste the example JSON from the REST service. You then create an import mapping using the just created JSON. This will also create the non persistent objects for you if you want to. Now you can use a REST call action where you provide the URL and if needed your account and password or API key to do a GET action on that URL. And the response can then eiter be put in a string or mapped directly using the created import mapping.

All is also explained in this academy lesson here: https://academy.mendix.com/link/modules/138/lectures/1226/5.1-Consume-a-REST-Service

Regards,

Ronald

 

answered
0

Hi Ronald,

 

Thanks for your reply. I already did all those steps and could get the list of the countries from the REST API. That's not the issue.

 

image.png

 

What I try to achieve is having an entity (let's say a 'Trip') referencing a country with a 1..* association (1 country, * trips). Here a my issues:

1. The association with a non persistent entity can only be in the not desired way

image.png

2. How can I use those objects in a form like this?

image.png

 

What I'd like to have is

- the combobox prefilled with all the countries

- the combobox preselected with the good country when I pass an object of type 'Trip'

- in the entity 'Trip', only store a unique code like the cca2 (or any other ISO code if i have it; this is just for the example).

 

I hope my question is clearer.

 

Thanks,

Gautier

 

answered