> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/umbraco-automate/18.latest/extending/custom-connection-type.md).

# Create a Custom Connection Type

A custom connection type lets actions in your project share reusable credentials for an external service. Each connection type defines:

* A **settings model** — the credential fields shown in the UI.
* A **validation method** — how to verify the credentials work.

## Settings Model

Mark sensitive fields with `IsSensitive = true` so the value is encrypted at rest and masked in run logs.

{% code title="MyServiceConnectionSettings.cs" %}

```csharp
using Umbraco.Automate.Core.Settings;

namespace MyProject.Automate;

public sealed class MyServiceConnectionSettings
{
    [Field(
        Label = "API endpoint",
        Description = "The base URL for the API.")]
    public string Endpoint { get; set; } = string.Empty;

    [Field(
        Label = "API key",
        Description = "The API key issued by the service.",
        IsSensitive = true)]
    public string ApiKey { get; set; } = string.Empty;
}
```

{% endcode %}

## Connection Type Class

Inherit from `ConnectionTypeBase<TSettings>` and override `ValidateAsync` to test the credentials.

{% code title="MyServiceConnectionType.cs" %}

```csharp
using Umbraco.Automate.Core.Connections;

namespace MyProject.Automate;

[ConnectionType("myService", "My Service",
    Description = "Connect to My Service",
    Group = "Custom",
    Icon = "icon-plug")]
public sealed class MyServiceConnectionType : ConnectionTypeBase<MyServiceConnectionSettings>
{
    private readonly IHttpClientFactory _httpClientFactory;

    public MyServiceConnectionType(
        ConnectionTypeInfrastructure infrastructure,
        IHttpClientFactory httpClientFactory)
        : base(infrastructure)
    {
        _httpClientFactory = httpClientFactory;
    }

    public override async Task<ConnectionValidationResult> ValidateAsync(
        object? settings,
        CancellationToken cancellationToken)
    {
        if (settings is not MyServiceConnectionSettings typed)
        {
            return ConnectionValidationResult.Failure("Connection settings are missing.");
        }

        using var client = _httpClientFactory.CreateClient();
        client.DefaultRequestHeaders.Add("Authorization", $"Bearer {typed.ApiKey}");

        try
        {
            using var response = await client.GetAsync($"{typed.Endpoint}/ping", cancellationToken);
            return response.IsSuccessStatusCode
                ? ConnectionValidationResult.Success("Connected to My Service.")
                : ConnectionValidationResult.Failure($"My Service rejected the credentials: {response.ReasonPhrase}");
        }
        catch (Exception ex)
        {
            return ConnectionValidationResult.Failure("Could not reach My Service.", [ex.Message]);
        }
    }
}
```

{% endcode %}

## Registration

No manual registration is required. The connection type is discovered at startup by its `[ConnectionType]` attribute and the base class.

## Verify

Restart your Umbraco site. The new connection type appears in the connection type picker under the **Custom** group. Create a connection, click **Test connection**, and confirm the credentials work.

## See Also

* [Connections](/umbraco-automate/18.latest/concepts/connections.md)
* [Create a Custom Action](/umbraco-automate/18.latest/extending/custom-action.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.umbraco.com/umbraco-automate/18.latest/extending/custom-connection-type.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
