> For the complete documentation index, see [llms.txt](https://developers.docstudio.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.docstudio.com/guides/account-domains.md).

# Account Domains

This document contains account domain endpoints, including parameters, requests, responses, and status codes.

An account domain is a verified company email domain connected to a DocStudio account. It establishes the corporate environment in which an organization can create and manage corporate users, assign account and mailbox permissions, configure automatic mailbox creation, and apply corporate authentication rules.

The endpoints on this page manage the domain and its SAML2 or OAuth2 identity providers. They do not create users, mailboxes, roles, or permissions directly. For complete request and response schemas, parameter requirements, and status codes, use the [Swagger UI](https://api.docstudio.com/swagger-ui/index.html).

### Business goals

Account Domain endpoints support the following business goals:

* **Establish a corporate environment.** Register and verify that an organization controls a company email domain before using it for corporate user management.
* **Manage the domain lifecycle.** Retrieve, update, verify, activate, deactivate, check, or delete a domain configuration.
* **Configure corporate authentication.** Connect a SAML2 or OAuth2 identity provider to the domain and optionally require users from that domain to authenticate through SSO.
* **Automate administration.** Manage corporate domain and identity-provider configuration from an internal administration system instead of configuring it manually.

### Endpoint summary

#### Account domains

<table><thead><tr><th width="99.111083984375">Method</th><th width="332">Endpoint</th><th>Purpose</th></tr></thead><tbody><tr><td><code>GET</code></td><td><code>/api/v1/account/{accountUuid}/domain</code></td><td>Retrieve account domains or find them by name or status</td></tr><tr><td><code>POST</code></td><td><code>/api/v1/account/{accountUuid}/domain</code></td><td>Register a corporate email domain and optionally connect an identity provider</td></tr><tr><td><code>GET</code></td><td><code>/api/v1/account/{accountUuid}/domain/{domainUuid}</code></td><td>Retrieve one domain's current configuration and status</td></tr><tr><td><code>PUT</code></td><td><code>/api/v1/account/{accountUuid}/domain/{domainUuid}</code></td><td>Change the connected identity provider or the SSO-only login setting</td></tr><tr><td><code>PATCH</code></td><td><code>/api/v1/account/{accountUuid}/domain/{domainUuid}/{action}</code></td><td>Verify, confirm, activate, deactivate, or check the domain</td></tr><tr><td><code>DELETE</code></td><td><code>/api/v1/account/{accountUuid}/domain/{domainUuid}</code></td><td>Remove a domain that the organization no longer manages through the account</td></tr></tbody></table>

#### SAML2 identity providers

<table><thead><tr><th width="102.4444580078125">Method</th><th width="310">Endpoint</th><th>Purpose</th></tr></thead><tbody><tr><td><code>GET</code></td><td><code>/api/v1/account/{accountId}/saml-provider</code></td><td>Retrieve the SAML2 providers configured for the account</td></tr><tr><td><code>POST</code></td><td><code>/api/v1/account/{accountId}/saml-provider</code></td><td>Add a SAML2 provider before connecting it to a corporate domain</td></tr><tr><td><code>GET</code></td><td><code>/api/v1/account/{accountId}/saml-provider/{id}</code></td><td>Retrieve one SAML2 provider's complete configuration</td></tr><tr><td><code>PUT</code></td><td><code>/api/v1/account/{accountId}/saml-provider/{id}</code></td><td>Update SAML metadata, attribute mappings, certificates, or signing credentials</td></tr><tr><td><code>DELETE</code></td><td><code>/api/v1/account/{accountId}/saml-provider/{id}</code></td><td>Remove a SAML2 provider that is no longer used</td></tr></tbody></table>

#### OAuth2 identity providers

<table><thead><tr><th width="99">Method</th><th>Endpoint</th><th>Purpose</th></tr></thead><tbody><tr><td><code>GET</code></td><td><code>/api/v1/account/{accountId}/oauth-provider</code></td><td>Retrieve the OAuth2 providers configured for the account</td></tr><tr><td><code>POST</code></td><td><code>/api/v1/account/{accountId}/oauth-provider</code></td><td>Add an OAuth2 provider before connecting it to a corporate domain</td></tr><tr><td><code>GET</code></td><td><code>/api/v1/account/{accountId}/oauth-provider/{id}</code></td><td>Retrieve one OAuth2 provider's complete configuration</td></tr><tr><td><code>PUT</code></td><td><code>/api/v1/account/{accountId}/oauth-provider/{id}</code></td><td>Update client credentials, provider endpoints, issuer information, JWK settings, or scopes</td></tr><tr><td><code>DELETE</code></td><td><code>/api/v1/account/{accountId}/oauth-provider/{id}</code></td><td>Remove an OAuth2 provider that is no longer used</td></tr></tbody></table>

### Account domain lifecycle

A domain is first registered through `POST /api/v1/account/{accountUuid}/domain`. The request can include an identity-provider UUID and the `onlySsoLogin` setting, but the identity provider must already exist in the account.

```json
{
  "ssoIdProviderUuid": "{providerUuid}",
  "onlySsoLogin": true,
  "domain": "acme.com"
}
```

Use `GET /api/v1/account/{accountUuid}/domain/{domainUuid}` to retrieve the domain before changing its configuration. The response shows its current status, verification information, connected identity provider, and `onlySsoLogin` value.

Use `PUT /api/v1/account/{accountUuid}/domain/{domainUuid}` to replace the connected identity provider or change the SSO-only login setting without recreating the domain.

```json
{
  "ssoIdProviderUuid": "{providerUuid}",
  "onlySsoLogin": true
}
```

Use one endpoint for domain verification and status changes:

{% tabs %}
{% tab title="Node.js" %}

```javascript
const payload = {
  method: "DNS_TXT_RECORD"
};

const response = await fetch(
  "https://api.docstudio.com/api/v1/account/" +
    "{accountUuid}/domain/{domainUuid}/{action}",
  {
    method: "PATCH",
    headers: {
      Authorization: "Bearer {token}",
      "Content-Type": "application/json"
    },
    body: JSON.stringify(payload)
  }
);

const body = await response.text();

if (!response.ok) {
  throw new Error(
    `Request failed: ${response.status}\n${body}`
  );
}

if (body) {
  console.log(body);
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$payload = [
    "method" => "DNS_TXT_RECORD"
];

$url =
    "https://api.docstudio.com/api/v1/account/" .
    "{accountUuid}/domain/{domainUuid}/{action}";

$curl = curl_init($url);

curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => "PATCH",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer {token}",
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode($payload),
    CURLOPT_RETURNTRANSFER => true
]);

$body = curl_exec($curl);

if ($body === false) {
    throw new RuntimeException(curl_error($curl));
}

$status = curl_getinfo(
    $curl,
    CURLINFO_RESPONSE_CODE
);

curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException(
        "Request failed: {$status}\n{$body}"
    );
}

if ($body !== "") {
    echo $body;
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

response = requests.patch(
    "https://api.docstudio.com/api/v1/account/"
    "{accountUuid}/domain/{domainUuid}/{action}",
    headers={
        "Authorization": "Bearer {token}",
    },
    json={
        "method": "DNS_TXT_RECORD",
    },
    timeout=30,
)

response.raise_for_status()

if response.text:
    print(response.text)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "json"
require "net/http"
require "uri"

uri = URI(
  "https://api.docstudio.com/api/v1/account/" \
  "{accountUuid}/domain/{domainUuid}/{action}"
)

payload = {
  method: "DNS_TXT_RECORD"
}

request = Net::HTTP::Patch.new(uri)
request["Authorization"] = "Bearer {token}"
request["Content-Type"] = "application/json"
request.body = JSON.generate(payload)

response = Net::HTTP.start(
  uri.hostname,
  uri.port,
  use_ssl: true
) do |http|
  http.request(request)
end

unless response.is_a?(Net::HTTPSuccess)
  raise "Request failed: #{response.code}\n#{response.body}"
end

puts response.body unless response.body.empty?
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	payload := map[string]string{
		"method": "DNS_TXT_RECORD",
	}

	requestBody, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}

	url := "https://api.docstudio.com/api/v1/account/" +
		"{accountUuid}/domain/{domainUuid}/{action}"

	request, err := http.NewRequest(
		http.MethodPatch,
		url,
		bytes.NewReader(requestBody),
	)
	if err != nil {
		panic(err)
	}

	request.Header.Set(
		"Authorization",
		"Bearer {token}",
	)
	request.Header.Set(
		"Content-Type",
		"application/json",
	)

	response, err := http.DefaultClient.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		panic(err)
	}

	if response.StatusCode < 200 ||
		response.StatusCode >= 300 {
		panic(fmt.Sprintf(
			"Request failed: %s\n%s",
			response.Status,
			body,
		))
	}

	if len(body) > 0 {
		fmt.Println(string(body))
	}
}
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
  public static void main(String[] args) throws Exception {
    String url =
        "https://api.docstudio.com/api/v1/account/"
        + "{accountUuid}/domain/{domainUuid}/{action}";

    String payload = """
        {
          "method": "DNS_TXT_RECORD"
        }
        """;

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(url))
        .header(
            "Authorization",
            "Bearer {token}"
        )
        .header(
            "Content-Type",
            "application/json"
        )
        .method(
            "PATCH",
            HttpRequest.BodyPublishers.ofString(payload)
        )
        .build();

    HttpResponse<String> response =
        HttpClient.newHttpClient().send(
            request,
            HttpResponse.BodyHandlers.ofString()
        );

    if (response.statusCode() < 200 ||
        response.statusCode() >= 300) {
      throw new RuntimeException(
          "Request failed: " +
          response.statusCode() +
          "\n" +
          response.body()
      );
    }

    if (!response.body().isEmpty()) {
      System.out.println(response.body());
    }
  }
}
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var client = new HttpClient();

var payload = new
{
    method = "DNS_TXT_RECORD"
};

var url =
    "https://api.docstudio.com/api/v1/account/" +
    "{accountUuid}/domain/{domainUuid}/{action}";

using var request = new HttpRequestMessage(
    HttpMethod.Patch,
    url
);

request.Headers.Authorization =
    new AuthenticationHeaderValue(
        "Bearer",
        "{token}"
    );

request.Content = new StringContent(
    JsonSerializer.Serialize(payload),
    Encoding.UTF8,
    "application/json"
);

using var response =
    await client.SendAsync(request);

var body =
    await response.Content.ReadAsStringAsync();

if (!response.IsSuccessStatusCode)
{
    throw new HttpRequestException(
        $"Request failed: " +
        $"{(int)response.StatusCode}\n{body}"
    );
}

if (!string.IsNullOrEmpty(body))
{
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request PATCH \
  --url 'https://api.docstudio.com/api/v1/account/{accountUuid}/domain/{domainUuid}/{action}' \
  --header 'Authorization: Bearer {token}' \
  --header 'Content-Type: application/json' \
  --data '{
    "method": "DNS_TXT_RECORD"
  }'
```

{% endtab %}
{% endtabs %}

Supported `{action}` values:

<table><thead><tr><th width="235">Action</th><th>Purpose</th></tr></thead><tbody><tr><td><code>verify</code></td><td>Start or update DNS-based domain verification</td></tr><tr><td><code>confirm</code></td><td>Confirm verification after configuring the required DNS record</td></tr><tr><td><code>activate</code></td><td>Activate the verified domain</td></tr><tr><td><code>deactivate</code></td><td>Disable the domain without deleting its configuration</td></tr><tr><td><code>check</code></td><td>Check the current verification state</td></tr></tbody></table>

Use `DNS_TXT_RECORD` or `DNS_CNAME_RECORD` as the request body `method`.

### Identity-provider configuration

SAML2 provider endpoints are intended for organizations that authenticate users through a SAML-compatible identity provider. The configuration includes SAML metadata, user attribute mappings, a signing certificate, and a signing private key.

OAuth2 provider endpoints are intended for organizations that use OAuth2 or OpenID Connect authentication. The configuration includes the client ID and secret, authorization and token endpoints, issuer URI, JWK set URI, and requested scopes.

After creating a provider, use its UUID as `ssoIdProviderUuid` when creating or updating an account domain. Set `onlySsoLogin` to `true` when users from the domain must authenticate through the connected corporate provider.

{% hint style="warning" %}
Provider configurations may contain signing private keys or OAuth2 client secrets. Store these values securely. Do not include real credentials in source code, application logs, or public documentation.
{% endhint %}

### Practical example: Configure a corporate domain with SAML2 SSO

A company uses `acme.com` email addresses and wants its corporate users to authenticate through its SAML2 identity provider. The integration must create the provider, register and verify the domain, connect the provider, and activate the domain.

#### Create the SAML2 provider

{% tabs %}
{% tab title="Node.js" %}

```javascript
const provider = {
  id: "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
  name: "Acme SAML",
  firstNameMapping: "givenName",
  lastNameMapping: "surname",
  phoneMapping: "telephoneNumber",
  metadataUrl: "https://idp.acme.com/saml/metadata",
  metadataXml: "{metadataXml}",
  signingCertificate: "{signingCertificate}",
  signingPrivateKey: "{signingPrivateKey}"
};

const response = await fetch(
  "https://api.docstudio.com/api/v1/account/" +
    "{accountId}/saml-provider",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer {token}",
      "Content-Type": "application/json"
    },
    body: JSON.stringify(provider)
  }
);

const body = await response.text();

if (!response.ok) {
  throw new Error(
    `Request failed: ${response.status}\n${body}`
  );
}

if (body) {
  console.log(body);
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$provider = [
    "id" => "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
    "name" => "Acme SAML",
    "firstNameMapping" => "givenName",
    "lastNameMapping" => "surname",
    "phoneMapping" => "telephoneNumber",
    "metadataUrl" => "https://idp.acme.com/saml/metadata",
    "metadataXml" => "{metadataXml}",
    "signingCertificate" => "{signingCertificate}",
    "signingPrivateKey" => "{signingPrivateKey}"
];

$url =
    "https://api.docstudio.com/api/v1/account/" .
    "{accountId}/saml-provider";

$curl = curl_init($url);

curl_setopt_array($curl, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer {token}",
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode($provider),
    CURLOPT_RETURNTRANSFER => true
]);

$body = curl_exec($curl);

if ($body === false) {
    throw new RuntimeException(curl_error($curl));
}

$status = curl_getinfo(
    $curl,
    CURLINFO_RESPONSE_CODE
);

curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException(
        "Request failed: {$status}\n{$body}"
    );
}

if ($body !== "") {
    echo $body;
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

provider = {
    "id": "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
    "name": "Acme SAML",
    "firstNameMapping": "givenName",
    "lastNameMapping": "surname",
    "phoneMapping": "telephoneNumber",
    "metadataUrl": "https://idp.acme.com/saml/metadata",
    "metadataXml": "{metadataXml}",
    "signingCertificate": "{signingCertificate}",
    "signingPrivateKey": "{signingPrivateKey}",
}

response = requests.post(
    "https://api.docstudio.com/api/v1/account/"
    "{accountId}/saml-provider",
    headers={
        "Authorization": "Bearer {token}",
    },
    json=provider,
    timeout=30,
)

response.raise_for_status()

if response.text:
    print(response.text)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "json"
require "net/http"
require "uri"

uri = URI(
  "https://api.docstudio.com/api/v1/account/" \
  "{accountId}/saml-provider"
)

provider = {
  id: "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
  name: "Acme SAML",
  firstNameMapping: "givenName",
  lastNameMapping: "surname",
  phoneMapping: "telephoneNumber",
  metadataUrl: "https://idp.acme.com/saml/metadata",
  metadataXml: "{metadataXml}",
  signingCertificate: "{signingCertificate}",
  signingPrivateKey: "{signingPrivateKey}"
}

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer {token}"
request["Content-Type"] = "application/json"
request.body = JSON.generate(provider)

response = Net::HTTP.start(
  uri.hostname,
  uri.port,
  use_ssl: true
) do |http|
  http.request(request)
end

unless response.is_a?(Net::HTTPSuccess)
  raise "Request failed: #{response.code}\n#{response.body}"
end

puts response.body unless response.body.empty?
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	provider := map[string]string{
		"id":                 "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
		"name":               "Acme SAML",
		"firstNameMapping":   "givenName",
		"lastNameMapping":    "surname",
		"phoneMapping":       "telephoneNumber",
		"metadataUrl":        "https://idp.acme.com/saml/metadata",
		"metadataXml":        "{metadataXml}",
		"signingCertificate": "{signingCertificate}",
		"signingPrivateKey":  "{signingPrivateKey}",
	}

	requestBody, err := json.Marshal(provider)
	if err != nil {
		panic(err)
	}

	url := "https://api.docstudio.com/api/v1/account/" +
		"{accountId}/saml-provider"

	request, err := http.NewRequest(
		http.MethodPost,
		url,
		bytes.NewReader(requestBody),
	)
	if err != nil {
		panic(err)
	}

	request.Header.Set(
		"Authorization",
		"Bearer {token}",
	)
	request.Header.Set(
		"Content-Type",
		"application/json",
	)

	response, err := http.DefaultClient.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		panic(err)
	}

	if response.StatusCode < 200 ||
		response.StatusCode >= 300 {
		panic(fmt.Sprintf(
			"Request failed: %s\n%s",
			response.Status,
			body,
		))
	}

	if len(body) > 0 {
		fmt.Println(string(body))
	}
}
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
  public static void main(String[] args) throws Exception {
    String url =
        "https://api.docstudio.com/api/v1/account/"
        + "{accountId}/saml-provider";

    String payload = """
        {
          "id": "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
          "name": "Acme SAML",
          "firstNameMapping": "givenName",
          "lastNameMapping": "surname",
          "phoneMapping": "telephoneNumber",
          "metadataUrl": "https://idp.acme.com/saml/metadata",
          "metadataXml": "{metadataXml}",
          "signingCertificate": "{signingCertificate}",
          "signingPrivateKey": "{signingPrivateKey}"
        }
        """;

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(url))
        .header(
            "Authorization",
            "Bearer {token}"
        )
        .header(
            "Content-Type",
            "application/json"
        )
        .POST(
            HttpRequest.BodyPublishers.ofString(payload)
        )
        .build();

    HttpResponse<String> response =
        HttpClient.newHttpClient().send(
            request,
            HttpResponse.BodyHandlers.ofString()
        );

    if (response.statusCode() < 200 ||
        response.statusCode() >= 300) {
      throw new RuntimeException(
          "Request failed: " +
          response.statusCode() +
          "\n" +
          response.body()
      );
    }

    if (!response.body().isEmpty()) {
      System.out.println(response.body());
    }
  }
}
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var client = new HttpClient();

var provider = new
{
    id = "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
    name = "Acme SAML",
    firstNameMapping = "givenName",
    lastNameMapping = "surname",
    phoneMapping = "telephoneNumber",
    metadataUrl = "https://idp.acme.com/saml/metadata",
    metadataXml = "{metadataXml}",
    signingCertificate = "{signingCertificate}",
    signingPrivateKey = "{signingPrivateKey}"
};

var url =
    "https://api.docstudio.com/api/v1/account/" +
    "{accountId}/saml-provider";

using var request = new HttpRequestMessage(
    HttpMethod.Post,
    url
);

request.Headers.Authorization =
    new AuthenticationHeaderValue(
        "Bearer",
        "{token}"
    );

request.Content = new StringContent(
    JsonSerializer.Serialize(provider),
    Encoding.UTF8,
    "application/json"
);

using var response =
    await client.SendAsync(request);

var body =
    await response.Content.ReadAsStringAsync();

if (!response.IsSuccessStatusCode)
{
    throw new HttpRequestException(
        $"Request failed: " +
        $"{(int)response.StatusCode}\n{body}"
    );
}

if (!string.IsNullOrEmpty(body))
{
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request POST \
  --url 'https://api.docstudio.com/api/v1/account/{accountId}/saml-provider' \
  --header 'Authorization: Bearer {token}' \
  --header 'Content-Type: application/json' \
  --data '{
    "id": "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
    "name": "Acme SAML",
    "firstNameMapping": "givenName",
    "lastNameMapping": "surname",
    "phoneMapping": "telephoneNumber",
    "metadataUrl": "https://idp.acme.com/saml/metadata",
    "metadataXml": "{metadataXml}",
    "signingCertificate": "{signingCertificate}",
    "signingPrivateKey": "{signingPrivateKey}"
  }'
```

{% endtab %}
{% endtabs %}

#### Register the domain

Use the provider UUID as `ssoIdProviderUuid`. Enabling `onlySsoLogin` requires users from the domain to use the connected provider.

{% tabs %}
{% tab title="Node.js" %}

```javascript
const domain = {
  ssoIdProviderUuid:
    "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
  onlySsoLogin: true,
  domain: "acme.com"
};

const response = await fetch(
  "https://api.docstudio.com/api/v1/account/" +
    "{accountUuid}/domain",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer {token}",
      "Content-Type": "application/json"
    },
    body: JSON.stringify(domain)
  }
);

const body = await response.text();

if (!response.ok) {
  throw new Error(
    `Request failed: ${response.status}\n${body}`
  );
}

if (body) {
  console.log(body);
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$domain = [
    "ssoIdProviderUuid" =>
        "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
    "onlySsoLogin" => true,
    "domain" => "acme.com"
];

$url =
    "https://api.docstudio.com/api/v1/account/" .
    "{accountUuid}/domain";

$curl = curl_init($url);

curl_setopt_array($curl, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer {token}",
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode($domain),
    CURLOPT_RETURNTRANSFER => true
]);

$body = curl_exec($curl);

if ($body === false) {
    throw new RuntimeException(curl_error($curl));
}

$status = curl_getinfo(
    $curl,
    CURLINFO_RESPONSE_CODE
);

curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException(
        "Request failed: {$status}\n{$body}"
    );
}

if ($body !== "") {
    echo $body;
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

domain = {
    "ssoIdProviderUuid":
        "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
    "onlySsoLogin": True,
    "domain": "acme.com",
}

response = requests.post(
    "https://api.docstudio.com/api/v1/account/"
    "{accountUuid}/domain",
    headers={
        "Authorization": "Bearer {token}",
    },
    json=domain,
    timeout=30,
)

response.raise_for_status()

if response.text:
    print(response.text)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "json"
require "net/http"
require "uri"

uri = URI(
  "https://api.docstudio.com/api/v1/account/" \
  "{accountUuid}/domain"
)

domain = {
  ssoIdProviderUuid:
    "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
  onlySsoLogin: true,
  domain: "acme.com"
}

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer {token}"
request["Content-Type"] = "application/json"
request.body = JSON.generate(domain)

response = Net::HTTP.start(
  uri.hostname,
  uri.port,
  use_ssl: true
) do |http|
  http.request(request)
end

unless response.is_a?(Net::HTTPSuccess)
  raise "Request failed: #{response.code}\n#{response.body}"
end

puts response.body unless response.body.empty?
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	domain := map[string]any{
		"ssoIdProviderUuid":
			"68b95bf4-71a8-4fa4-b086-7fc32c187d71",
		"onlySsoLogin": true,
		"domain":       "acme.com",
	}

	requestBody, err := json.Marshal(domain)
	if err != nil {
		panic(err)
	}

	url := "https://api.docstudio.com/api/v1/account/" +
		"{accountUuid}/domain"

	request, err := http.NewRequest(
		http.MethodPost,
		url,
		bytes.NewReader(requestBody),
	)
	if err != nil {
		panic(err)
	}

	request.Header.Set(
		"Authorization",
		"Bearer {token}",
	)
	request.Header.Set(
		"Content-Type",
		"application/json",
	)

	response, err := http.DefaultClient.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		panic(err)
	}

	if response.StatusCode < 200 ||
		response.StatusCode >= 300 {
		panic(fmt.Sprintf(
			"Request failed: %s\n%s",
			response.Status,
			body,
		))
	}

	if len(body) > 0 {
		fmt.Println(string(body))
	}
}
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
  public static void main(String[] args) throws Exception {
    String url =
        "https://api.docstudio.com/api/v1/account/"
        + "{accountUuid}/domain";

    String payload = """
        {
          "ssoIdProviderUuid":
            "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
          "onlySsoLogin": true,
          "domain": "acme.com"
        }
        """;

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(url))
        .header(
            "Authorization",
            "Bearer {token}"
        )
        .header(
            "Content-Type",
            "application/json"
        )
        .POST(
            HttpRequest.BodyPublishers.ofString(payload)
        )
        .build();

    HttpResponse<String> response =
        HttpClient.newHttpClient().send(
            request,
            HttpResponse.BodyHandlers.ofString()
        );

    if (response.statusCode() < 200 ||
        response.statusCode() >= 300) {
      throw new RuntimeException(
          "Request failed: " +
          response.statusCode() +
          "\n" +
          response.body()
      );
    }

    if (!response.body().isEmpty()) {
      System.out.println(response.body());
    }
  }
}
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var client = new HttpClient();

var domain = new
{
    ssoIdProviderUuid =
        "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
    onlySsoLogin = true,
    domain = "acme.com"
};

var url =
    "https://api.docstudio.com/api/v1/account/" +
    "{accountUuid}/domain";

using var request = new HttpRequestMessage(
    HttpMethod.Post,
    url
);

request.Headers.Authorization =
    new AuthenticationHeaderValue(
        "Bearer",
        "{token}"
    );

request.Content = new StringContent(
    JsonSerializer.Serialize(domain),
    Encoding.UTF8,
    "application/json"
);

using var response =
    await client.SendAsync(request);

var body =
    await response.Content.ReadAsStringAsync();

if (!response.IsSuccessStatusCode)
{
    throw new HttpRequestException(
        $"Request failed: " +
        $"{(int)response.StatusCode}\n{body}"
    );
}

if (!string.IsNullOrEmpty(body))
{
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request POST \
  --url 'https://api.docstudio.com/api/v1/account/{accountUuid}/domain' \
  --header 'Authorization: Bearer {token}' \
  --header 'Content-Type: application/json' \
  --data '{
    "ssoIdProviderUuid": "68b95bf4-71a8-4fa4-b086-7fc32c187d71",
    "onlySsoLogin": true,
    "domain": "acme.com"
  }'
```

{% endtab %}
{% endtabs %}

#### Verify and activate the domain

Use the `domainUuid` returned when the domain was created. Run `verify`, `confirm`, and `activate` in that order. Configure the returned DNS record before running `confirm`.

{% tabs %}
{% tab title="Node.js" %}

```javascript
const payload = {
  method: "DNS_TXT_RECORD"
};

const response = await fetch(
  "https://api.docstudio.com/api/v1/account/" +
    "{accountUuid}/domain/{domainUuid}/{action}",
  {
    method: "PATCH",
    headers: {
      Authorization: "Bearer {token}",
      "Content-Type": "application/json"
    },
    body: JSON.stringify(payload)
  }
);

const body = await response.text();

if (!response.ok) {
  throw new Error(
    `Request failed: ${response.status}\n${body}`
  );
}

if (body) {
  console.log(body);
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$payload = [
    "method" => "DNS_TXT_RECORD"
];

$url =
    "https://api.docstudio.com/api/v1/account/" .
    "{accountUuid}/domain/{domainUuid}/{action}";

$curl = curl_init($url);

curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => "PATCH",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer {token}",
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode($payload),
    CURLOPT_RETURNTRANSFER => true
]);

$body = curl_exec($curl);

if ($body === false) {
    throw new RuntimeException(curl_error($curl));
}

$status = curl_getinfo(
    $curl,
    CURLINFO_RESPONSE_CODE
);

curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException(
        "Request failed: {$status}\n{$body}"
    );
}

if ($body !== "") {
    echo $body;
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

response = requests.patch(
    "https://api.docstudio.com/api/v1/account/"
    "{accountUuid}/domain/{domainUuid}/{action}",
    headers={
        "Authorization": "Bearer {token}",
    },
    json={
        "method": "DNS_TXT_RECORD",
    },
    timeout=30,
)

response.raise_for_status()

if response.text:
    print(response.text)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "json"
require "net/http"
require "uri"

uri = URI(
  "https://api.docstudio.com/api/v1/account/" \
  "{accountUuid}/domain/{domainUuid}/{action}"
)

payload = {
  method: "DNS_TXT_RECORD"
}

request = Net::HTTP::Patch.new(uri)
request["Authorization"] = "Bearer {token}"
request["Content-Type"] = "application/json"
request.body = JSON.generate(payload)

response = Net::HTTP.start(
  uri.hostname,
  uri.port,
  use_ssl: true
) do |http|
  http.request(request)
end

unless response.is_a?(Net::HTTPSuccess)
  raise "Request failed: #{response.code}\n#{response.body}"
end

puts response.body unless response.body.empty?
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	payload := map[string]string{
		"method": "DNS_TXT_RECORD",
	}

	requestBody, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}

	url := "https://api.docstudio.com/api/v1/account/" +
		"{accountUuid}/domain/{domainUuid}/{action}"

	request, err := http.NewRequest(
		http.MethodPatch,
		url,
		bytes.NewReader(requestBody),
	)
	if err != nil {
		panic(err)
	}

	request.Header.Set(
		"Authorization",
		"Bearer {token}",
	)
	request.Header.Set(
		"Content-Type",
		"application/json",
	)

	response, err := http.DefaultClient.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		panic(err)
	}

	if response.StatusCode < 200 ||
		response.StatusCode >= 300 {
		panic(fmt.Sprintf(
			"Request failed: %s\n%s",
			response.Status,
			body,
		))
	}

	if len(body) > 0 {
		fmt.Println(string(body))
	}
}
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
  public static void main(String[] args) throws Exception {
    String url =
        "https://api.docstudio.com/api/v1/account/"
        + "{accountUuid}/domain/{domainUuid}/{action}";

    String payload = """
        {
          "method": "DNS_TXT_RECORD"
        }
        """;

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(url))
        .header(
            "Authorization",
            "Bearer {token}"
        )
        .header(
            "Content-Type",
            "application/json"
        )
        .method(
            "PATCH",
            HttpRequest.BodyPublishers.ofString(payload)
        )
        .build();

    HttpResponse<String> response =
        HttpClient.newHttpClient().send(
            request,
            HttpResponse.BodyHandlers.ofString()
        );

    if (response.statusCode() < 200 ||
        response.statusCode() >= 300) {
      throw new RuntimeException(
          "Request failed: " +
          response.statusCode() +
          "\n" +
          response.body()
      );
    }

    if (!response.body().isEmpty()) {
      System.out.println(response.body());
    }
  }
}
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var client = new HttpClient();

var payload = new
{
    method = "DNS_TXT_RECORD"
};

var url =
    "https://api.docstudio.com/api/v1/account/" +
    "{accountUuid}/domain/{domainUuid}/{action}";

using var request = new HttpRequestMessage(
    HttpMethod.Patch,
    url
);

request.Headers.Authorization =
    new AuthenticationHeaderValue(
        "Bearer",
        "{token}"
    );

request.Content = new StringContent(
    JsonSerializer.Serialize(payload),
    Encoding.UTF8,
    "application/json"
);

using var response =
    await client.SendAsync(request);

var body =
    await response.Content.ReadAsStringAsync();

if (!response.IsSuccessStatusCode)
{
    throw new HttpRequestException(
        $"Request failed: " +
        $"{(int)response.StatusCode}\n{body}"
    );
}

if (!string.IsNullOrEmpty(body))
{
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request PATCH \
  --url 'https://api.docstudio.com/api/v1/account/{accountUuid}/domain/{domainUuid}/{action}' \
  --header 'Authorization: Bearer {token}' \
  --header 'Content-Type: application/json' \
  --data '{
    "method": "DNS_TXT_RECORD"
  }'
```

{% endtab %}
{% endtabs %}

Retrieve the domain to check its current configuration and status:

```http
GET /api/v1/account/{accountUuid}/domain/{domainUuid}
Authorization: Bearer {token}
```

### Practical example: Move a domain from SAML2 to OAuth2

A company already has a corporate domain but is replacing its SAML2 provider with an OAuth2 provider. The domain does not need to be recreated because its connected provider can be changed through the update endpoint.

#### Create the OAuth2 provider

{% tabs %}
{% tab title="Node.js" %}

```javascript
const provider = {
  id: "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
  name: "Acme OAuth2",
  clientId: "docstudio-client",
  clientSecret: "{clientSecret}",
  authorizationUri:
    "https://login.acme.com/oauth2/authorize",
  tokenUri:
    "https://login.acme.com/oauth2/token",
  issuerUri: "https://login.acme.com",
  jwkSetUri:
    "https://login.acme.com/.well-known/jwks.json",
  scopes: "openid profile email"
};

const response = await fetch(
  "https://api.docstudio.com/api/v1/account/" +
    "{accountId}/oauth-provider",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer {token}",
      "Content-Type": "application/json"
    },
    body: JSON.stringify(provider)
  }
);

const body = await response.text();

if (!response.ok) {
  throw new Error(
    `Request failed: ${response.status}\n${body}`
  );
}

if (body) {
  console.log(body);
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$provider = [
    "id" => "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
    "name" => "Acme OAuth2",
    "clientId" => "docstudio-client",
    "clientSecret" => "{clientSecret}",
    "authorizationUri" =>
        "https://login.acme.com/oauth2/authorize",
    "tokenUri" =>
        "https://login.acme.com/oauth2/token",
    "issuerUri" => "https://login.acme.com",
    "jwkSetUri" =>
        "https://login.acme.com/.well-known/jwks.json",
    "scopes" => "openid profile email"
];

$url =
    "https://api.docstudio.com/api/v1/account/" .
    "{accountId}/oauth-provider";

$curl = curl_init($url);

curl_setopt_array($curl, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer {token}",
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode($provider),
    CURLOPT_RETURNTRANSFER => true
]);

$body = curl_exec($curl);

if ($body === false) {
    throw new RuntimeException(curl_error($curl));
}

$status = curl_getinfo(
    $curl,
    CURLINFO_RESPONSE_CODE
);

curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException(
        "Request failed: {$status}\n{$body}"
    );
}

if ($body !== "") {
    echo $body;
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

provider = {
    "id": "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
    "name": "Acme OAuth2",
    "clientId": "docstudio-client",
    "clientSecret": "{clientSecret}",
    "authorizationUri":
        "https://login.acme.com/oauth2/authorize",
    "tokenUri":
        "https://login.acme.com/oauth2/token",
    "issuerUri": "https://login.acme.com",
    "jwkSetUri":
        "https://login.acme.com/.well-known/jwks.json",
    "scopes": "openid profile email",
}

response = requests.post(
    "https://api.docstudio.com/api/v1/account/"
    "{accountId}/oauth-provider",
    headers={
        "Authorization": "Bearer {token}",
    },
    json=provider,
    timeout=30,
)

response.raise_for_status()

if response.text:
    print(response.text)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "json"
require "net/http"
require "uri"

uri = URI(
  "https://api.docstudio.com/api/v1/account/" \
  "{accountId}/oauth-provider"
)

provider = {
  id: "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
  name: "Acme OAuth2",
  clientId: "docstudio-client",
  clientSecret: "{clientSecret}",
  authorizationUri:
    "https://login.acme.com/oauth2/authorize",
  tokenUri:
    "https://login.acme.com/oauth2/token",
  issuerUri: "https://login.acme.com",
  jwkSetUri:
    "https://login.acme.com/.well-known/jwks.json",
  scopes: "openid profile email"
}

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer {token}"
request["Content-Type"] = "application/json"
request.body = JSON.generate(provider)

response = Net::HTTP.start(
  uri.hostname,
  uri.port,
  use_ssl: true
) do |http|
  http.request(request)
end

unless response.is_a?(Net::HTTPSuccess)
  raise "Request failed: #{response.code}\n#{response.body}"
end

puts response.body unless response.body.empty?
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	provider := map[string]string{
		"id":
			"c42a5f61-cecf-4ef0-b3ad-4956d3555049",
		"name":
			"Acme OAuth2",
		"clientId":
			"docstudio-client",
		"clientSecret":
			"{clientSecret}",
		"authorizationUri":
			"https://login.acme.com/oauth2/authorize",
		"tokenUri":
			"https://login.acme.com/oauth2/token",
		"issuerUri":
			"https://login.acme.com",
		"jwkSetUri":
			"https://login.acme.com/.well-known/jwks.json",
		"scopes":
			"openid profile email",
	}

	requestBody, err := json.Marshal(provider)
	if err != nil {
		panic(err)
	}

	url := "https://api.docstudio.com/api/v1/account/" +
		"{accountId}/oauth-provider"

	request, err := http.NewRequest(
		http.MethodPost,
		url,
		bytes.NewReader(requestBody),
	)
	if err != nil {
		panic(err)
	}

	request.Header.Set(
		"Authorization",
		"Bearer {token}",
	)
	request.Header.Set(
		"Content-Type",
		"application/json",
	)

	response, err := http.DefaultClient.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		panic(err)
	}

	if response.StatusCode < 200 ||
		response.StatusCode >= 300 {
		panic(fmt.Sprintf(
			"Request failed: %s\n%s",
			response.Status,
			body,
		))
	}

	if len(body) > 0 {
		fmt.Println(string(body))
	}
}
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
  public static void main(String[] args) throws Exception {
    String url =
        "https://api.docstudio.com/api/v1/account/"
        + "{accountId}/oauth-provider";

    String payload = """
        {
          "id": "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
          "name": "Acme OAuth2",
          "clientId": "docstudio-client",
          "clientSecret": "{clientSecret}",
          "authorizationUri":
            "https://login.acme.com/oauth2/authorize",
          "tokenUri":
            "https://login.acme.com/oauth2/token",
          "issuerUri": "https://login.acme.com",
          "jwkSetUri":
            "https://login.acme.com/.well-known/jwks.json",
          "scopes": "openid profile email"
        }
        """;

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(url))
        .header(
            "Authorization",
            "Bearer {token}"
        )
        .header(
            "Content-Type",
            "application/json"
        )
        .POST(
            HttpRequest.BodyPublishers.ofString(payload)
        )
        .build();

    HttpResponse<String> response =
        HttpClient.newHttpClient().send(
            request,
            HttpResponse.BodyHandlers.ofString()
        );

    if (response.statusCode() < 200 ||
        response.statusCode() >= 300) {
      throw new RuntimeException(
          "Request failed: " +
          response.statusCode() +
          "\n" +
          response.body()
      );
    }

    if (!response.body().isEmpty()) {
      System.out.println(response.body());
    }
  }
}
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var client = new HttpClient();

var provider = new
{
    id = "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
    name = "Acme OAuth2",
    clientId = "docstudio-client",
    clientSecret = "{clientSecret}",
    authorizationUri =
        "https://login.acme.com/oauth2/authorize",
    tokenUri =
        "https://login.acme.com/oauth2/token",
    issuerUri = "https://login.acme.com",
    jwkSetUri =
        "https://login.acme.com/.well-known/jwks.json",
    scopes = "openid profile email"
};

var url =
    "https://api.docstudio.com/api/v1/account/" +
    "{accountId}/oauth-provider";

using var request = new HttpRequestMessage(
    HttpMethod.Post,
    url
);

request.Headers.Authorization =
    new AuthenticationHeaderValue(
        "Bearer",
        "{token}"
    );

request.Content = new StringContent(
    JsonSerializer.Serialize(provider),
    Encoding.UTF8,
    "application/json"
);

using var response =
    await client.SendAsync(request);

var body =
    await response.Content.ReadAsStringAsync();

if (!response.IsSuccessStatusCode)
{
    throw new HttpRequestException(
        $"Request failed: " +
        $"{(int)response.StatusCode}\n{body}"
    );
}

if (!string.IsNullOrEmpty(body))
{
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request POST \
  --url 'https://api.docstudio.com/api/v1/account/{accountId}/oauth-provider' \
  --header 'Authorization: Bearer {token}' \
  --header 'Content-Type: application/json' \
  --data '{
    "id": "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
    "name": "Acme OAuth2",
    "clientId": "docstudio-client",
    "clientSecret": "{clientSecret}",
    "authorizationUri": "https://login.acme.com/oauth2/authorize",
    "tokenUri": "https://login.acme.com/oauth2/token",
    "issuerUri": "https://login.acme.com",
    "jwkSetUri": "https://login.acme.com/.well-known/jwks.json",
    "scopes": "openid profile email"
  }'
```

{% endtab %}
{% endtabs %}

#### Connect the new provider to the domain

{% tabs %}
{% tab title="Node.js" %}

```javascript
const update = {
  ssoIdProviderUuid:
    "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
  onlySsoLogin: true
};

const response = await fetch(
  "https://api.docstudio.com/api/v1/account/" +
    "{accountUuid}/domain/{domainUuid}",
  {
    method: "PUT",
    headers: {
      Authorization: "Bearer {token}",
      "Content-Type": "application/json"
    },
    body: JSON.stringify(update)
  }
);

const body = await response.text();

if (!response.ok) {
  throw new Error(
    `Request failed: ${response.status}\n${body}`
  );
}

if (body) {
  console.log(body);
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$update = [
    "ssoIdProviderUuid" =>
        "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
    "onlySsoLogin" => true
];

$url =
    "https://api.docstudio.com/api/v1/account/" .
    "{accountUuid}/domain/{domainUuid}";

$curl = curl_init($url);

curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => "PUT",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer {token}",
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode($update),
    CURLOPT_RETURNTRANSFER => true
]);

$body = curl_exec($curl);

if ($body === false) {
    throw new RuntimeException(curl_error($curl));
}

$status = curl_getinfo(
    $curl,
    CURLINFO_RESPONSE_CODE
);

curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException(
        "Request failed: {$status}\n{$body}"
    );
}

if ($body !== "") {
    echo $body;
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

update = {
    "ssoIdProviderUuid":
        "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
    "onlySsoLogin": True,
}

response = requests.put(
    "https://api.docstudio.com/api/v1/account/"
    "{accountUuid}/domain/{domainUuid}",
    headers={
        "Authorization": "Bearer {token}",
    },
    json=update,
    timeout=30,
)

response.raise_for_status()

if response.text:
    print(response.text)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "json"
require "net/http"
require "uri"

uri = URI(
  "https://api.docstudio.com/api/v1/account/" \
  "{accountUuid}/domain/{domainUuid}"
)

update = {
  ssoIdProviderUuid:
    "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
  onlySsoLogin: true
}

request = Net::HTTP::Put.new(uri)
request["Authorization"] = "Bearer {token}"
request["Content-Type"] = "application/json"
request.body = JSON.generate(update)

response = Net::HTTP.start(
  uri.hostname,
  uri.port,
  use_ssl: true
) do |http|
  http.request(request)
end

unless response.is_a?(Net::HTTPSuccess)
  raise "Request failed: #{response.code}\n#{response.body}"
end

puts response.body unless response.body.empty?
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	update := map[string]any{
		"ssoIdProviderUuid":
			"c42a5f61-cecf-4ef0-b3ad-4956d3555049",
		"onlySsoLogin": true,
	}

	requestBody, err := json.Marshal(update)
	if err != nil {
		panic(err)
	}

	url := "https://api.docstudio.com/api/v1/account/" +
		"{accountUuid}/domain/{domainUuid}"

	request, err := http.NewRequest(
		http.MethodPut,
		url,
		bytes.NewReader(requestBody),
	)
	if err != nil {
		panic(err)
	}

	request.Header.Set(
		"Authorization",
		"Bearer {token}",
	)
	request.Header.Set(
		"Content-Type",
		"application/json",
	)

	response, err := http.DefaultClient.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		panic(err)
	}

	if response.StatusCode < 200 ||
		response.StatusCode >= 300 {
		panic(fmt.Sprintf(
			"Request failed: %s\n%s",
			response.Status,
			body,
		))
	}

	if len(body) > 0 {
		fmt.Println(string(body))
	}
}
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
  public static void main(String[] args) throws Exception {
    String url =
        "https://api.docstudio.com/api/v1/account/"
        + "{accountUuid}/domain/{domainUuid}";

    String payload = """
        {
          "ssoIdProviderUuid":
            "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
          "onlySsoLogin": true
        }
        """;

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(url))
        .header(
            "Authorization",
            "Bearer {token}"
        )
        .header(
            "Content-Type",
            "application/json"
        )
        .PUT(
            HttpRequest.BodyPublishers.ofString(payload)
        )
        .build();

    HttpResponse<String> response =
        HttpClient.newHttpClient().send(
            request,
            HttpResponse.BodyHandlers.ofString()
        );

    if (response.statusCode() < 200 ||
        response.statusCode() >= 300) {
      throw new RuntimeException(
          "Request failed: " +
          response.statusCode() +
          "\n" +
          response.body()
      );
    }

    if (!response.body().isEmpty()) {
      System.out.println(response.body());
    }
  }
}
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

using var client = new HttpClient();

var update = new
{
    ssoIdProviderUuid =
        "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
    onlySsoLogin = true
};

var url =
    "https://api.docstudio.com/api/v1/account/" +
    "{accountUuid}/domain/{domainUuid}";

using var request = new HttpRequestMessage(
    HttpMethod.Put,
    url
);

request.Headers.Authorization =
    new AuthenticationHeaderValue(
        "Bearer",
        "{token}"
    );

request.Content = new StringContent(
    JsonSerializer.Serialize(update),
    Encoding.UTF8,
    "application/json"
);

using var response =
    await client.SendAsync(request);

var body =
    await response.Content.ReadAsStringAsync();

if (!response.IsSuccessStatusCode)
{
    throw new HttpRequestException(
        $"Request failed: " +
        $"{(int)response.StatusCode}\n{body}"
    );
}

if (!string.IsNullOrEmpty(body))
{
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request PUT \
  --url 'https://api.docstudio.com/api/v1/account/{accountUuid}/domain/{domainUuid}' \
  --header 'Authorization: Bearer {token}' \
  --header 'Content-Type: application/json' \
  --data '{
    "ssoIdProviderUuid": "c42a5f61-cecf-4ef0-b3ad-4956d3555049",
    "onlySsoLogin": true
  }'
```

{% endtab %}
{% endtabs %}

Remove the previous SAML2 provider only after no domain uses it:

```http
DELETE /api/v1/account/{accountId}/saml-provider/{id}
Authorization: Bearer {token}
```

### Related topics

* [Authorization](/api-reference/authorization.md)
* [Error handling and API error codes](/error-codes/error-handling-and-api-error-codes.md)
