This is the official documentation of Forest Admin Cloud.
After executing an action, the UI will display a notification message based on the HTTP status code received.
To make the code easier to read, all the code snippets below should be wrapped in the following code. Ensure you update the collection and action names as needed.
The resultBuilder argument passed to the execution function enables you to customize the response of an action.
returnresultBuilder.success('Company is now live!');
returnresultBuilder.error('Company was already live!');
HTML response
Additionally, you can return an HTML response to present richer content.
returnresultBuilder.success('Success', { html:` <h2 style="color: #dc3545; text-align: center;">Contact Banned Successfully!</h2> <p style="font-size: 16px; color: #333; text-align: center;"> An automated email has been sent to the user detailing the reason for the ban. The user has a 30-day window to dispute the decision in order to prevent a permanent ban on the platform. </p> `,});
File response
You can also provide a downloadable file as a response to a triggered action.
To use this feature, you have to include generateFile: true within the action's definition.
Webhooks enable triggering actions in third-party applications or starting background tasks for users, using HTTP/HTTPS callbacks. Triggers occur in the user's browser, thus are subject to CORS restrictions.
returnresultBuilder.webhook('https://mywebhookurl.someapp.com',// Webhook URL.'POST',// Webhook method (typically a POST). {},// Webhook headers. {},// Webhook body (only JSON is supported).);
Modifying HTTP Headers
It is possible to change the HTTP response headers by using the setHeader() function.
After calling setHeader(), you can call any response method previously described, such as:
return resultBuilder.setHeader('myHeaderName','myHeaderValue').success('Contact is now banned!').
It's important to understand that the webhook() function and the setHeader() function serve different purposes. The former sends headers with the webhook call, while the latter modifies the headers of the HTTP response. These operations do not interfere with each other.