dan-bucko-9DXo7yCT6mc-unsplash.jpg
Cover image for olawale

Omosekeji Olawale Verified userVerified user

Technical Support Engineer

Appsmith

Dynamic Binding in Appsmith

When writing queries in Appsmith, it becomes very demanding when you want to use dynamic values within your Queries, API values, and Search Parameters. 
Appsmith Allows you to use Dynamic Bindings within Query parameters, API Paths and Headers, and Search Parameters. 
 

 

A General Overview. 
 


Dynamic Bindings in Appsmith is possible with the use of the mustache syntax {{ appsmith.store.<SAVED_KEY>}} with Widgets, Queries, and APIs. With this, during evaluation, Appsmith replaces {{appsmith.store.<SAVED_KEY>}} with the actual value you have in your store, which gives you endless possibilities as to how you want your queries structured. 

Please follow this link to learn more about binding data to widgets in Appsmith 


Dynamic Binding in Query Parameters. 


Using dynamic binding in query parameters is very straightforward. With SQL-related data sources, it looks something like this: 
INSERT INTO USERS (name) VALUES ('{{Input_Widget.text}}'). This will eventually evaluate to something like INSERT INTO USERS (name) VALUES('olawale') because of the dynamic binding capacity provided by Appsmith. Moderate evaluations can also be done within the binding to make Appsmith evaluate to specific values based on certain conditions. For example, INSERT INTO users (name) VALUES ("{{appsmith.user.email == 'olawale@appsmith.com' ? Input_Widget.text : 'NOT_ALLOWED' }}")  inserts the value of Input_Widget.text into the database if the currently logged-in user email is olawale@appsmith.com. Otherwise, it just inserts NOT_ALLOWED.


Dynamic Binding in API Path and Headers


Using dynamic binding in API URL paths is exactly like that of API URLs and headers. The approach is to use the mustache syntax to replace the part of the URL you want to be dynamic like so: https://jsonplaceholder.typicode.com/{{appsmith.store.url_sub_path}}


 

Dynamic Binding in Datasource Configurations. 


Unfortunately, this has been deprecated since version 1.9.21 of Appsmith. The recommended way to go about this is to use the multiple-data source-environment feature of Appsmith. 
 

pratimadudhewar public View pratimadudhewar's profile
Thu, 06/06/2024 - 07:34

Hello,

 

I want to send dynamic sessionToken in header section of other API's. After getting sessionToken, i have stored it in a store object. But in headers how can i access that value?

Ron Northcutt Verified userVerified user staff View ron's profile
Tue, 06/11/2024 - 16:05

You can call the stored value in the header field like this:

{{ appsmith.store.KEY_NAME }}