Response
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.

Simple response
The resultBuilder
argument passed to the execution
function enables you to customize the response of an action.
return resultBuilder.success('Company is now live!');

return resultBuilder.error('Company was already live!');

HTML response
Additionally, you can return an HTML response to present richer content.
return resultBuilder.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.
collection.addAction('Ban user', {
scope: 'Single',
generateFile: true,
execute: async (context, resultBuilder) => {
// ...
Inline content
return resultBuilder.file('The content of the file', 'filename.txt', 'text/plain');
Buffer content
const buffer = Buffer.from('The content of the file');
return resultBuilder.file(buffer, 'filename.txt', 'text/plain');
Stream content
const stream = fs.createReadStream('path/to/file');
return resultBuilder.file(stream, 'filename.txt', 'text/plain');
Making a redirection
You can redirect to another location after triggering an action.
return resultBuilder.redirectTo(
'/MyProject/Production/Operations/data/contacts/index',
);
Triggering a Webhook
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.
return resultBuilder.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.
return resultBuilder.setHeader('myHeaderName', 'myHeaderValue')
After calling setHeader()
, you can call any response method previously described, such as:
return resultBuilder
.setHeader('myHeaderName', 'myHeaderValue')
.success('Contact is now banned!').
Last updated
Was this helpful?