# Response

{% hint style="success" %}
This is the official documentation of Forest Admin Cloud.
{% endhint %}

After executing an action, the UI will display a notification message based on the HTTP status code received.

![](/files/RpkVPvLd3gOf1gTVauNp)

***

{% hint style="info" %}
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.

```typescript
import type { Agent } from '@forestadmin/forest-cloud';
import { Schema } from '../typings';

export default function customizeAgent(agent: Agent<Schema>) {
  agent.customizeCollection('contacts', (collection) => {
    collection.addAction('Ban user', {
      scope: 'Single',
      execute: async (context, resultBuilder) => {
        // Insert the code snippet here.
      },
    });
  });
}
```

{% endhint %}

### Simple response

The `resultBuilder` argument passed to the `execution` function enables you to customize the response of an action.

```typescript
return resultBuilder.success('Company is now live!');
```

![](/files/ZgAKSYkHmwM6MMjemowa)

***

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

![](/files/DnCUseZz6x7AiJHos6Ck)

***

### HTML response

Additionally, you can return an HTML response to present richer content.

<pre class="language-typescript"><code class="lang-typescript"><strong>return resultBuilder.success('Success', {
</strong>  html: `
    &#x3C;h2 style="color: #dc3545; text-align: center;">Contact Banned Successfully!&#x3C;/h2>
    &#x3C;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.
    &#x3C;/p>
  `,
});
</code></pre>

<figure><img src="/files/pmE0QgufqwAwqtzx5ePZ" alt=""><figcaption></figcaption></figure>

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

```typescript
collection.addAction('Ban user', {
  scope: 'Single',
  generateFile: true,
  execute: async (context, resultBuilder) => {
  // ...
```

#### **Inline content**

```typescript
return resultBuilder.file('The content of the file', 'filename.txt', 'text/plain');
```

#### **Buffer content**

```typescript
const buffer = Buffer.from('The content of the file');
return resultBuilder.file(buffer, 'filename.txt', 'text/plain');
```

#### **Stream content**

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
return resultBuilder.setHeader('myHeaderName', 'myHeaderValue')
```

After calling `setHeader()`, you can call any response method previously described, such as:

```typescript
return resultBuilder
    .setHeader('myHeaderName', 'myHeaderValue')
    .success('Contact is now banned!').
```

{% hint style="info" %}
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.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/cloud/code-customization/actions/response.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
