#URL param value white space not working in appsmith however it works fine in Postman or browser.
1 messages · Page 1 of 1 (latest)
Hello! I'm AppyHelper, your support bot for Appsmith queries.
It sounds like you're facing an issue with URL encoding in Appsmith when your API has parameters with spaces. In URLs, spaces must be encoded. Typically, spaces in a URL should be replaced with %20 or +.
For your specific case, if the parameter value includes spaces, such as "Pending Validation", you should encode it in the URL. Here's how you can modify your API URL in Appsmith:
Alternatively, you can use JavaScript within Appsmith to dynamically encode URL parameters. Here?s an example of how you can do this using a JS function inside a JSObject:
export default {
encodeUrl: () => {
const baseUrl = "http://alpha.com/_query?";
const params = {
"param[dateA]": "",
"param[dateTo]": "date",
"param[rel_frm_rec_dat_fro]": "",
"param[status]": encodeURIComponent("Pending Validation")
};
const queryString = new URLSearchParams(params).toString();
return baseUrl + queryString;
}
}
Then, in your API configuration, you can use this function to set the URL:
{?{ JSObject1.encodeUrl() }?}
This approach ensures that all parameters are correctly encoded for web transmission.
If you don't find my response helpful, you can request to speak to a human agent.
but it is still not working even after using the default encoding
If the default URL encoding approach isn't resolving the issue, it's possible that there might be additional encoding requirements or other issues with how the API is being called from Appsmith. Let's try a different approach to ensure that all parameters are correctly encoded and the API request is set up properly.
You can manually encode each parameter using JavaScript in Appsmith and construct the URL dynamically. Here?s how you can set up a JS function to handle this:
export default {
constructUrl: () => {
const baseUrl = "http://alpha.com/_query?";
const params = {
"param[dateA]": "",
"param[dateTo]": "date",
"param[rel_frm_rec_dat_fro]": "",
"param[status]": "Pending Validation"
};
const encodedParams = Object.keys(params).map(key =>
encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
).join('&');
return baseUrl + encodedParams;
}
}
Then, use this function in your API configuration:
{?{ JSObject1.constructUrl() }?}
This method ensures that both the keys and the values are encoded correctly, which might solve the issue if there are special characters in the keys as well.
If this still does not resolve the issue, it might be helpful to check the network requests from Appsmith using the browser's developer tools (Network tab) to compare the request being made by Appsmith with the one from Postman. This comparison might reveal discrepancies in headers, method, body, or how parameters are being sent.
If you don't find my response helpful, you can request to speak to a human agent.
Please share the following information to help us debug this issue:
- What is your Appsmith version?
- Send us a loom.com screen recording showing the exact steps you take and the issue in action.
- If possible, please share this app with us to debug this scenario. Add [email protected] as a Developer and send us the link to it.
Appsmith version is v1.27