> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# NSWebhookAgent

> Webhook definitions* webhooks signal other systems about events inside NetServer.

Webhook definitions\* webhooks signal other systems about events inside NetServer.

## Constructors

### NSWebhookAgent()

```crmscript theme={null}
NSWebhookAgent
```

## Methods

## CreateDefaultWebhook()

Sets default values into a new NSWebhook.

```crmscript theme={null}
NSWebhook CreateDefaultWebhook()
```

**Returns:** [CRMScript.NetServer.NSWebhook](CRMScript.NetServer.NSWebhook) - A new NSWebhook with default values.

<Note>
  NetServer calculates default values (for example, Country) on the entity, which is required when creating/storing a new instance
</Note>

**Example:**

```crmscript theme={null}
NSWebhookAgent agent;
NSWebhook thing = agent.CreateDefaultWebhook();
thing = agent.SaveWebhook(thing);
```

## DeleteWebhook(Integer)

Deletes the NSWebhook

```crmscript theme={null}
DeleteWebhook(Integer webhook)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSWebhookAgent agent;
agent.DeleteWebhook(123);
```

## GetAllWebhooks(String,String,Integer)

Returns all webhooks, according to filter criteria

```crmscript theme={null}
NSWebhook[] GetAllWebhooks(String nameFilter, String eventFilter, Integer statusFilter)
```

**Returns:** [CRMScript.NetServer.NSWebhook](CRMScript.NetServer.NSWebhook)\[]

**Example:**

```crmscript theme={null}
NSWebhookAgent agent;
String nameFilter;
String eventFilter;
Integer statusFilter;
NSWebhook[] res = agent.GetAllWebhooks(nameFilter, eventFilter, statusFilter);
```

## GetLastError(Integer)

Return the most recent error message received when calling this webhook.

```crmscript theme={null}
String GetLastError(Integer webhookId)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String)

**Example:**

```crmscript theme={null}
NSWebhookAgent agent;
Integer webhookId;
String res = agent.GetLastError(webhookId);
```

## GetWebhook(Integer)

Gets an NSWebhook object.

```crmscript theme={null}
NSWebhook GetWebhook(Integer webhookId)
```

**Returns:** [CRMScript.NetServer.NSWebhook](CRMScript.NetServer.NSWebhook)

**Example:**

```crmscript theme={null}
NSWebhookAgent agent;
NSWebhook thing = agent.GetWebhook(123);
```

## SaveWebhook(NSWebhook)

Updates the existing NSWebhook or creates a new NSWebhook if the id parameter is 0

```crmscript theme={null}
NSWebhook SaveWebhook(NSWebhook webhook)
```

**Returns:** [CRMScript.NetServer.NSWebhook](CRMScript.NetServer.NSWebhook)

**Example:**

```crmscript theme={null}
NSWebhook  agent;
NSWebhook thing = agent.CreateDefaultWebhook();
thing = agent.SaveWebhook(thing);
```

## SignalEvent(String,Integer,StringObjectDictionary)

Signal webhooks that an event has occurred. All webhooks listening for the event will be notified.

```crmscript theme={null}
Void SignalEvent(String eventName, Integer primaryKey, StringObjectDictionary data)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
NSWebhookAgent agent;
String eventName;
Integer primaryKey;
StringObjectDictionary data;
agent.SignalEvent(eventName, primaryKey, data);
```

## TestWebhook(NSWebhook)

Pings a webhook with a 'test' event, returns SUCCESS(true) or FAILURE(false) + the response from the webhook target.

```crmscript theme={null}
NSWebhookResult TestWebhook(NSWebhook webhook)
```

**Returns:** [CRMScript.NetServer.NSWebhookResult](CRMScript.NetServer.NSWebhookResult)

**Example:**

```crmscript theme={null}
NSWebhookAgent agent;
NSWebhook webhook;
NSWebhookResult res = agent.TestWebhook(webhook);
```


## Related topics

- [Troubleshooting webhooks](/en/automation/webhook/dev/troubleshooting.md)
- [CRMScript webhooks event handlers](/en/automation/webhook/dev/crmscript-handlers.md)
- [Webhook subscription](/en/automation/webhook/dev/subscription.md)
- [SuperOffice.WebApi.Agents.WebhookAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.WebhookAgent.md)
- [SuperOffice.WebApi.Agents.IWebhookAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.IWebhookAgent.md)
- [Webhook](/en/api/archive-providers/reference/webhook.md)
