Dynamically Changing API Response with Login User Information
This tutorial explains how to dynamically change API endpoint responses using login user information. We will change the display content of the news list according to the logged-in user, with the following configuration:
- Add Company Name to Member Extension
- Add Target Company to Content (Notification)
- Add Custom Processing to Set Login User Information to Filter Query
- Allow Filter Requests and Set Up Pre-processing for the Endpoint
Add Company Name to Member Extension
Click [Member] -> [Member].
Click [Advanced Member Settings].
Click [Configure field settings for members].
Configure as follows and click [Update].
Item | Setting |
---|---|
Item name | Company Name |
Identifier | company_id |
Setting | Single choice |
1::Company A 2::Company B |
Click the name of the test member for operation check on the Member List page.
On the member editing page, set the company name in the profile information tab.
Add Target Company to Content (news)
Click [Content Structure].
Click on [news] from the content structure list.
On the content structure edit screen, set as follows and click [Update].
Item | Setting |
---|---|
Parent item | No selection |
Item name | Target |
Item setting | Multiple choice |
1::Company A 2::Company B 3::Company C |
The added items will be displayed on the content editing screen, so check the target company name and update it.
Add custom processing to set login user information to filter query
Next, add custom processing to get login user information.
Click [Operation] > [Custom function].
Click [Add].
Set as follows, and click [Add].
Item | Setting |
---|---|
Title | Add login user information to filter query |
Identifier | set_filter_request |
Process | Code below |
{if $smarty.session.super_flg ne 1}
{assign_member_detail var='mem' member_id=$smarty.session.member_id}
{assign var=request.filter value="ext_1 contains `$mem.company_id_key`"}
{/if}
For details on the notation of the filter parameter, see Using the filter query function.
Allow Filter Requests and Set Up Pre-processing for the Endpoint
Click on the API that has the endpoint to retrieve the list of news.
Click on [Update] for the endpoint that retrieves the list of news.
Enter ext_1
in the filter_request_allow_list
parameter, and then click [Update].
Next, click on [Pre-processing].
Set the category to "Uncategorized" and select "Add login user information to filter query" from the list.
Verify the Operation
Finally, verify the operation. After logging in, check the news list page to confirm that the contents of the displayed list are filtered.
Note that the operation cannot be confirmed with Swagger UI, so please confirm it in a browser. Reference FAQ: How do I verify requests that cannot be verified with Swagger UI?
Support
If you have any other questions, please contact us or check out Our Slack Community.