Call an API
- Go to your Mendix app. Left click on “Main” on the left side, then click “Add microflow…”. Name it “REST_Call”, then click “OK”.
Drag a “Microflow call” from the Toolbox onto your flow.
- Double-click on the “Call microflow” box, click “Select…”, then search for “ACT_ClientToken_GetToken”. This is a microflow included in the BYU starter app that generates an API token. Select this microflow, then click “OK”.
Drag a “Call REST service” from the Toolbox onto your flow.
- In a browser, go to developer.byu.edu/api-search.
- Search for Persons v3 and open the API documentation.
Scroll down until you find the API that takes in a BYU ID.
- Click "GET", then copy the URL shown.
In your Mendix app, in the REST_Call microflow, double click on the “Call REST (GET)” item. Next to “Location”, click “Edit…”. Paste the API URL and replace “{byu_id}” with your BYU ID. If there is no “v3” in the URL, make sure to add it so it looks like this.
- Click "OK", then open the "HTTP Headers" tab. Create a new Custom HTTP Header.
Enter "Authorization" for the key and "$ClientToken/Token" for the value.
- Click “OK”, then “OK” again to exit the popups.
Go back to BYU Developer Portal. On the right side, copy the JSON structure for the API.
- In Mendix, right click on Main, then click on Add other > JSON structure. Name it “Persons_Structure”.
- Delete the empty braces and paste the JSON structure we copied from the developer portal.
Under "Structure", click "Refresh"
- Click "OK".
- Right-click on Main, then click on Add other > Import mapping. Name it “Persons_Mapping”.
- Select “JSON structure”, then select “Persons_Structure”.
Under “Schema elements”, uncheck “(Object)”, then select “first_name” and “value” under "basic". Click "OK"
- Click “Map automatically…” at the top of the screen.
- Open your “REST_Call” microflow and open the “Call REST (GET)” widget.
- Open the “Response” tab. Set “Response handling” to “Apply import mapping”.
Set the import mapping to “Persons_Mapping”. Select “Yes” under “Store in variable” and change the variable name to “FirstName”. It should look like this.
- Open the end event of your microflow.
- Change the return type to “Object”
- Set the entity to “Main.First_name”
Set the return value to $FirstName. Click “OK”. Your final microflow should look like this.