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

# SuperOffice.WebApi.Agents.AgentBase

# \<a id="SuperOffice\_WebApi\_Agents\_AgentBase">\</a> Class AgentBase

Namespace: [SuperOffice.WebApi.Agents](SuperOffice.WebApi.Agents.md)\
Assembly: SuperOffice.WebApi.dll

Base class for client Agents. Uses a \<xref href="System.Net.Http.HttpClient" data-throw-if-not-resolved="false">\</xref> to call the SuperOffice REST API.
Will use a default implementation with gzip and progress callbacks if nothing is specified.

```csharp theme={null}
public class AgentBase : IAgentBase, IDisposable
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ←
[AgentBase](SuperOffice.WebApi.Agents.AgentBase.md)

#### Derived

[AIAgent](SuperOffice.WebApi.Agents.AIAgent.md),
[ApiAgent](SuperOffice.WebApi.Agents.ApiAgent.md),
[AppointmentAgent](SuperOffice.WebApi.Agents.AppointmentAgent.md),
[ArchiveAgent](SuperOffice.WebApi.Agents.ArchiveAgent.md),
[AssociateAgent](SuperOffice.WebApi.Agents.AssociateAgent.md),
[BLOBAgent](SuperOffice.WebApi.Agents.BLOBAgent.md),
[BatchAgent](SuperOffice.WebApi.Agents.BatchAgent.md),
[BulkUpdateAgent](SuperOffice.WebApi.Agents.BulkUpdateAgent.md),
[CRMScriptAgent](SuperOffice.WebApi.Agents.CRMScriptAgent.md),
[ChatAgent](SuperOffice.WebApi.Agents.ChatAgent.md),
[ConfigurationAgent](SuperOffice.WebApi.Agents.ConfigurationAgent.md),
[ContactAgent](SuperOffice.WebApi.Agents.ContactAgent.md),
[CustomObjectAgent](SuperOffice.WebApi.Agents.CustomObjectAgent.md),
[CustomerServiceAgent](SuperOffice.WebApi.Agents.CustomerServiceAgent.md),
[DashAgent](SuperOffice.WebApi.Agents.DashAgent.md),
[DashboardAgent](SuperOffice.WebApi.Agents.DashboardAgent.md),
[DatabaseAgent](SuperOffice.WebApi.Agents.DatabaseAgent.md),
[DatabaseTableAgent](SuperOffice.WebApi.Agents.DatabaseTableAgent.md),
[DiagnosticsAgent](SuperOffice.WebApi.Agents.DiagnosticsAgent.md),
[DocumentAgent](SuperOffice.WebApi.Agents.DocumentAgent.md),
[DocumentMigrationAgent](SuperOffice.WebApi.Agents.DocumentMigrationAgent.md),
[EMailAgent](SuperOffice.WebApi.Agents.EMailAgent.md),
[ErpSyncAgent](SuperOffice.WebApi.Agents.ErpSyncAgent.md),
[FavouriteAgent](SuperOffice.WebApi.Agents.FavouriteAgent.md),
[FindAgent](SuperOffice.WebApi.Agents.FindAgent.md),
[ForeignSystemAgent](SuperOffice.WebApi.Agents.ForeignSystemAgent.md),
[FreeTextAgent](SuperOffice.WebApi.Agents.FreeTextAgent.md),
[ImportAgent](SuperOffice.WebApi.Agents.ImportAgent.md),
[LicenseAgent](SuperOffice.WebApi.Agents.LicenseAgent.md),
[ListAgent](SuperOffice.WebApi.Agents.ListAgent.md),
[MDOAgent](SuperOffice.WebApi.Agents.MDOAgent.md),
[MarketingAgent](SuperOffice.WebApi.Agents.MarketingAgent.md),
[MessagingAgent](SuperOffice.WebApi.Agents.MessagingAgent.md),
[NavigatorAgent](SuperOffice.WebApi.Agents.NavigatorAgent.md),
[NewsFeedAgent](SuperOffice.WebApi.Agents.NewsFeedAgent.md),
[NumberAllocationAgent](SuperOffice.WebApi.Agents.NumberAllocationAgent.md),
[PersonAgent](SuperOffice.WebApi.Agents.PersonAgent.md),
[PhoneListAgent](SuperOffice.WebApi.Agents.PhoneListAgent.md),
[PocketAgent](SuperOffice.WebApi.Agents.PocketAgent.md),
[PreferenceAgent](SuperOffice.WebApi.Agents.PreferenceAgent.md),
[PreviewsAgent](SuperOffice.WebApi.Agents.PreviewsAgent.md),
[ProjectAgent](SuperOffice.WebApi.Agents.ProjectAgent.md),
[QuoteAgent](SuperOffice.WebApi.Agents.QuoteAgent.md),
[RelationAgent](SuperOffice.WebApi.Agents.RelationAgent.md),
[ReportAgent](SuperOffice.WebApi.Agents.ReportAgent.md),
[ResourceAgent](SuperOffice.WebApi.Agents.ResourceAgent.md),
[SaintAgent](SuperOffice.WebApi.Agents.SaintAgent.md),
[SaleAgent](SuperOffice.WebApi.Agents.SaleAgent.md),
[SelectionAgent](SuperOffice.WebApi.Agents.SelectionAgent.md),
[SentryAgent](SuperOffice.WebApi.Agents.SentryAgent.md),
[TargetsAgent](SuperOffice.WebApi.Agents.TargetsAgent.md),
[TicketAgent](SuperOffice.WebApi.Agents.TicketAgent.md),
[TimeZoneAgent](SuperOffice.WebApi.Agents.TimeZoneAgent.md),
[TooltipsAgent](SuperOffice.WebApi.Agents.TooltipsAgent.md),
[UserAgent](SuperOffice.WebApi.Agents.UserAgent.md),
[UserDefinedFieldInfoAgent](SuperOffice.WebApi.Agents.UserDefinedFieldInfoAgent.md),
[ViewStateAgent](SuperOffice.WebApi.Agents.ViewStateAgent.md),
[WebhookAgent](SuperOffice.WebApi.Agents.WebhookAgent.md),
[WorkflowAgent](SuperOffice.WebApi.Agents.WorkflowAgent.md)

#### Implements

[IAgentBase](SuperOffice.WebApi.Agents.IAgentBase.md),
[IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

#### Inherited Members

[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring),
[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object\)),
[object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object-system-object\)),
[object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals),
[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode),
[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype),
[object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone)

## Remarks

Disposes of the client when the agent is disposed, if no client provided to ctor.

## Constructors

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_\_ctor\_System\_String\_System\_Net\_Http\_HttpClient\_">\</a> AgentBase(string, HttpClient)

Agent base class.

```csharp theme={null}
protected AgentBase(string baseUrl, HttpClient httpClient = null)
```

#### Parameters

`baseUrl` [string](https://learn.microsoft.com/dotnet/api/system.string)

URL to web API endpoint

`httpClient` [HttpClient](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient)

client to use to communicate with endpoint. Will make a default http client if nothing is provided.

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_\_ctor\_SuperOffice\_WebApi\_WebApiOptions\_System\_Net\_Http\_HttpClient\_">\</a> AgentBase(WebApiOptions, HttpClient)

Agent base class.

```csharp theme={null}
protected AgentBase(WebApiOptions configuration, HttpClient httpClient = null)
```

#### Parameters

`configuration` [WebApiOptions](SuperOffice.WebApi.WebApiOptions.md)

Settings and URL to web API endpoint

`httpClient` [HttpClient](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient)

client to use to communicate with endpoint. Will make a default http client if nothing is provided.

## Fields

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_\_binary">\</a> \_binary

```csharp theme={null}
protected const string _binary = "application/octet-stream"
```

#### Field Value

[string](https://learn.microsoft.com/dotnet/api/system.string)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_\_client">\</a> \_client

```csharp theme={null}
protected HttpClient _client
```

#### Field Value

[HttpClient](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_\_config">\</a> \_config

```csharp theme={null}
protected WebApiOptions _config
```

#### Field Value

[WebApiOptions](SuperOffice.WebApi.WebApiOptions.md)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_\_disposeClient">\</a> \_disposeClient

```csharp theme={null}
protected bool _disposeClient
```

#### Field Value

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_\_json">\</a> \_json

```csharp theme={null}
protected const string _json = "application/json"
```

#### Field Value

[string](https://learn.microsoft.com/dotnet/api/system.string)

## Properties

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_Client">\</a> Client

The HTTP Client we are using.
Create a default SO HttpClient if not specified in constructor.

```csharp theme={null}
protected HttpClient Client { get; }
```

#### Property Value

[HttpClient](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_ClientCancellationTokenSource">\</a> ClientCancellationTokenSource

Used in SendRequest to allow clients to cancel requests.

```csharp theme={null}
protected CancellationTokenSource ClientCancellationTokenSource { get; set; }
```

#### Property Value

[CancellationTokenSource](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtokensource)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_Configuration">\</a> Configuration

Configuration this agent was initalized with.

```csharp theme={null}
public WebApiOptions Configuration { get; }
```

#### Property Value

[WebApiOptions](SuperOffice.WebApi.WebApiOptions.md)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_HasRunningRequest">\</a> HasRunningRequest

Is an HTTP request in flight?

```csharp theme={null}
public bool HasRunningRequest { get; }
```

#### Property Value

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_ProgressListener">\</a> ProgressListener

Progress callback receiver for downloads

```csharp theme={null}
public IProgressListener ProgressListener { get; set; }
```

#### Property Value

[IProgressListener](SuperOffice.WebApi.IProgressListener.md)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_UploadProgressListener">\</a> UploadProgressListener

Progress callback receiver for uploads

```csharp theme={null}
public IProgressListener UploadProgressListener { get; set; }
```

#### Property Value

[IProgressListener](SuperOffice.WebApi.IProgressListener.md)

## Methods

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_BuildRequestFromObject\_System\_Net\_Http\_HttpMethod\_System\_String\_System\_Object\_SuperOffice\_WebApi\_WebApiOptions\_System\_String\_">\</a> BuildRequestFromObject(HttpMethod, string, object, WebApiOptions, string)

```csharp theme={null}
protected HttpRequestMessage BuildRequestFromObject(HttpMethod method, string url, object body, WebApiOptions config, string contentType)
```

#### Parameters

`method` [HttpMethod](https://learn.microsoft.com/dotnet/api/system.net.http.httpmethod)

`url` [string](https://learn.microsoft.com/dotnet/api/system.string)

`body` [object](https://learn.microsoft.com/dotnet/api/system.object)

`config` [WebApiOptions](SuperOffice.WebApi.WebApiOptions.md)

`contentType` [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Returns

[HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_BuildRequestFromObjectWithStream\_System\_Net\_Http\_HttpMethod\_System\_String\_System\_Object\_System\_IO\_Stream\_SuperOffice\_WebApi\_WebApiOptions\_System\_String\_">\</a> BuildRequestFromObjectWithStream(HttpMethod, string, object, Stream, WebApiOptions, string)

```csharp theme={null}
protected HttpRequestMessage BuildRequestFromObjectWithStream(HttpMethod method, string url, object body, Stream stream, WebApiOptions config, string contentType)
```

#### Parameters

`method` [HttpMethod](https://learn.microsoft.com/dotnet/api/system.net.http.httpmethod)

`url` [string](https://learn.microsoft.com/dotnet/api/system.string)

`body` [object](https://learn.microsoft.com/dotnet/api/system.object)

`stream` [Stream](https://learn.microsoft.com/dotnet/api/system.io.stream)

`config` [WebApiOptions](SuperOffice.WebApi.WebApiOptions.md)

`contentType` [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Returns

[HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_BuildRequestFromStream\_System\_Net\_Http\_HttpMethod\_System\_String\_System\_IO\_Stream\_SuperOffice\_WebApi\_WebApiOptions\_System\_String\_">\</a> BuildRequestFromStream(HttpMethod, string, Stream, WebApiOptions, string)

```csharp theme={null}
protected HttpRequestMessage BuildRequestFromStream(HttpMethod method, string url, Stream body, WebApiOptions config, string contentType)
```

#### Parameters

`method` [HttpMethod](https://learn.microsoft.com/dotnet/api/system.net.http.httpmethod)

`url` [string](https://learn.microsoft.com/dotnet/api/system.string)

`body` [Stream](https://learn.microsoft.com/dotnet/api/system.io.stream)

`config` [WebApiOptions](SuperOffice.WebApi.WebApiOptions.md)

`contentType` [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Returns

[HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_CancelRequest">\</a> CancelRequest()

Used by the client to terminate the current method call.

```csharp theme={null}
public void CancelRequest()
```

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_Dispose">\</a> Dispose()

Disposes of the HTTP Client if we own it.

```csharp theme={null}
public void Dispose()
```

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_Finally\_SuperOffice\_WebApi\_RequestOptions\_">\</a> Finally(RequestOptions)

```csharp theme={null}
protected void Finally(RequestOptions options)
```

#### Parameters

`options` [RequestOptions](SuperOffice.WebApi.RequestOptions.md)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_Merge\_SuperOffice\_WebApi\_RequestOptions\_">\</a> Merge(RequestOptions)

```csharp theme={null}
protected WebApiOptions Merge(RequestOptions options)
```

#### Parameters

`options` [RequestOptions](SuperOffice.WebApi.RequestOptions.md)

#### Returns

[WebApiOptions](SuperOffice.WebApi.WebApiOptions.md)

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_ParseAuthorization\_SuperOffice\_WebApi\_Authorization\_IAuthorization\_">\</a> ParseAuthorization(IAuthorization)

Creates authentication headers based on \<xref href="SuperOffice.WebApi.Authorization.IAuthorization" data-throw-if-not-resolved="false">\</xref> scheme and parameter.

```csharp theme={null}
protected AuthenticationHeaderValue ParseAuthorization(IAuthorization authorization)
```

#### Parameters

`authorization` IAuthorization

Contains authorization scheme and parameter values.

#### Returns

[AuthenticationHeaderValue](https://learn.microsoft.com/dotnet/api/system.net.http.headers.authenticationheadervalue)

Authorization header.

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_ParseResponse\_\_1\_System\_Net\_Http\_HttpResponseMessage\_">\</a> ParseResponse\<T\&gt;(HttpResponseMessage)

```csharp theme={null}
protected Task<T> ParseResponse<T>(HttpResponseMessage response)
```

#### Parameters

`response` [HttpResponseMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage)

#### Returns

[Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1)\<T\&gt;

#### Type Parameters

`T`

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_SendRequest\_System\_Net\_Http\_HttpRequestMessage\_SuperOffice\_WebApi\_RequestOptions\_">\</a> SendRequest(HttpRequestMessage, RequestOptions)

```csharp theme={null}
protected Task<HttpResponseMessage> SendRequest(HttpRequestMessage request, RequestOptions config)
```

#### Parameters

`request` [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage)

`config` [RequestOptions](SuperOffice.WebApi.RequestOptions.md)

#### Returns

[Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1)\<[HttpResponseMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage)\&gt;

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_SendRequestObject\_System\_Net\_Http\_HttpMethod\_System\_String\_System\_Object\_SuperOffice\_WebApi\_WebApiOptions\_System\_String\_">\</a> SendRequestObject(HttpMethod, string, object, WebApiOptions, string)

```csharp theme={null}
protected Task<HttpResponseMessage> SendRequestObject(HttpMethod method, string url, object args, WebApiOptions config, string contentType)
```

#### Parameters

`method` [HttpMethod](https://learn.microsoft.com/dotnet/api/system.net.http.httpmethod)

`url` [string](https://learn.microsoft.com/dotnet/api/system.string)

`args` [object](https://learn.microsoft.com/dotnet/api/system.object)

`config` [WebApiOptions](SuperOffice.WebApi.WebApiOptions.md)

`contentType` [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Returns

[Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1)\<[HttpResponseMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage)\&gt;

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_SendRequestObjectWithStream\_System\_Net\_Http\_HttpMethod\_System\_String\_System\_Object\_System\_IO\_Stream\_SuperOffice\_WebApi\_WebApiOptions\_System\_String\_">\</a> SendRequestObjectWithStream(HttpMethod, string, object, Stream, WebApiOptions, string)

```csharp theme={null}
protected Task<HttpResponseMessage> SendRequestObjectWithStream(HttpMethod method, string url, object args, Stream stream, WebApiOptions config, string contentType)
```

#### Parameters

`method` [HttpMethod](https://learn.microsoft.com/dotnet/api/system.net.http.httpmethod)

`url` [string](https://learn.microsoft.com/dotnet/api/system.string)

`args` [object](https://learn.microsoft.com/dotnet/api/system.object)

`stream` [Stream](https://learn.microsoft.com/dotnet/api/system.io.stream)

`config` [WebApiOptions](SuperOffice.WebApi.WebApiOptions.md)

`contentType` [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Returns

[Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1)\<[HttpResponseMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage)\&gt;

### \<a id="SuperOffice\_WebApi\_Agents\_AgentBase\_ThrowOnResponseErrorAsync\_System\_Net\_Http\_HttpRequestMessage\_System\_Net\_Http\_HttpResponseMessage\_">\</a> ThrowOnResponseErrorAsync(HttpRequestMessage, HttpResponseMessage)

Return NULL on NOT-FOUND errors

```csharp theme={null}
protected Task ThrowOnResponseErrorAsync(HttpRequestMessage request, HttpResponseMessage response)
```

#### Parameters

`request` [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage)

`response` [HttpResponseMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage)

#### Returns

[Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)


## Related topics

- [SuperOffice.WebApi.Agents.AIAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.AIAgent.md)
- [SuperOffice.WebApi.Agents.BLOBAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.BLOBAgent.md)
- [SuperOffice.WebApi.Agents.MDOAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.MDOAgent.md)
- [SuperOffice.WebApi.Agents.ApiAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.ApiAgent.md)
- [SuperOffice.WebApi.Agents.WebhookAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.WebhookAgent.md)
- [SuperOffice.WebApi.Agents.DatabaseAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.DatabaseAgent.md)
