# Add or remove a custom domain

Every command on this page needs a [bearer token](/help/rest-api/reference/authentication/) and counts towards your [hourly limit](/help/rest-api/reference/rate-limits-and-errors/).

## Add custom domain

**POST**`https://api.sirv.com/v2/account/custom-domain`

Use this method to configure a custom CDN domain for an account alias.

Request body (JSON)

| Field | Type | Required | Example | Description |
| --- | --- | --- | --- | --- |
| `alias` | string | Yes | `my-account` | [Account name](/help/getting-started/account-name-subdomain/) (alias) that the domain serves. |
| `domain` | string | Yes | `cdn.example.com` | Your [custom domain](/help/getting-started/custom-domain/), for example cdn.example.com. |

Example request

-   [Node.js](#tab-panel-0-0)
-   [Python](#tab-panel-0-1)
-   [cURL](#tab-panel-0-2)
-   [Java](#tab-panel-0-3)
-   [C#](#tab-panel-0-4)
-   [PHP](#tab-panel-0-5)
-   [Go](#tab-panel-0-6)
-   [Ruby](#tab-panel-0-7)
-   [Swift](#tab-panel-0-8)

```js
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/account/custom-domain', {
  method: 'POST',
  headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' },
  body: JSON.stringify({
    "alias": "my-account",
    "domain": "cdn.example.com"
  }),
});
console.log(res.status, await res.text());
```

```python
import requests

res = requests.post(
    'https://api.sirv.com/v2/account/custom-domain',
    headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'},
    json={
      "alias": "my-account",
      "domain": "cdn.example.com"
    },
)
print(res.status_code, res.text)
```

```bash
curl --request POST \
  --url 'https://api.sirv.com/v2/account/custom-domain' \
  --header 'authorization: Bearer BEARER_TOKEN' \
  --header 'content-type: application/json' \
  --data '{"alias":"my-account","domain":"cdn.example.com"}'
```

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

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/account/custom-domain"))
    .header("authorization", "Bearer BEARER_TOKEN")
    .header("content-type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("""
        {
          "alias": "my-account",
          "domain": "cdn.example.com"
        }
        """))
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
```

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

using var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/account/custom-domain");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");
request.Content = new StringContent("""
{
  "alias": "my-account",
  "domain": "cdn.example.com"
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

```php
<?php
$ch = curl_init('https://api.sirv.com/v2/account/custom-domain');
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'],
  CURLOPT_POSTFIELDS => json_encode([
    'alias' => 'my-account',
    'domain' => 'cdn.example.com'
  ]),
  CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);
```

```go
package main

import (
  "fmt"
  "io"
  "net/http"
  "strings"
)

func main() {
  body := strings.NewReader(`{
    "alias": "my-account",
    "domain": "cdn.example.com"
  }`)
  req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/account/custom-domain", body)
  req.Header.Set("authorization", "Bearer BEARER_TOKEN")
  req.Header.Set("content-type", "application/json")
  res, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer res.Body.Close()
  out, _ := io.ReadAll(res.Body)
  fmt.Println(res.Status, string(out))
}
```

```ruby
require 'net/http'

uri = URI('https://api.sirv.com/v2/account/custom-domain')
req = Net::HTTP::Post.new(uri)
req['authorization'] = 'Bearer BEARER_TOKEN'
req['content-type'] = 'application/json'
req.body = <<~'JSON'
  {
    "alias": "my-account",
    "domain": "cdn.example.com"
  }
JSON
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts res.code, res.body
```

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/account/custom-domain")!)
request.httpMethod = "POST"
request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")
request.setValue("application/json", forHTTPHeaderField: "content-type")
request.httpBody = #"""
{
  "alias": "my-account",
  "domain": "cdn.example.com"
}
"""#.data(using: .utf8)
let (data, response) = try await URLSession.shared.data(for: request)
print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))
```

Response

HTTP 200 with an empty body when the command succeeds.

## Remove custom domain

**DELETE**`https://api.sirv.com/v2/account/custom-domain`

Use this method to remove the custom CDN domain from an account alias.

Query parameters

| Name | Type | Required | Example | Description |
| --- | --- | --- | --- | --- |
| `alias` | string | Yes | `my-account` | Account name (alias) that the domain serves. |
| `domain` | string | Yes | `cdn.example.com` | Custom domain to remove. |

Example request

-   [Node.js](#tab-panel-1-0)
-   [Python](#tab-panel-1-1)
-   [cURL](#tab-panel-1-2)
-   [Java](#tab-panel-1-3)
-   [C#](#tab-panel-1-4)
-   [PHP](#tab-panel-1-5)
-   [Go](#tab-panel-1-6)
-   [Ruby](#tab-panel-1-7)
-   [Swift](#tab-panel-1-8)

```js
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/account/custom-domain?alias=my-account&domain=cdn.example.com', {
  method: 'DELETE',
  headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());
```

```python
import requests

res = requests.delete(
    'https://api.sirv.com/v2/account/custom-domain?alias=my-account&domain=cdn.example.com',
    headers={'authorization': 'Bearer BEARER_TOKEN'},
)
print(res.status_code, res.text)
```

```bash
curl --request DELETE \
  --url 'https://api.sirv.com/v2/account/custom-domain?alias=my-account&domain=cdn.example.com' \
  --header 'authorization: Bearer BEARER_TOKEN'
```

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

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/account/custom-domain?alias=my-account&domain=cdn.example.com"))
    .header("authorization", "Bearer BEARER_TOKEN")
    .method("DELETE", HttpRequest.BodyPublishers.noBody())
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
```

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

using var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("DELETE"), "https://api.sirv.com/v2/account/custom-domain?alias=my-account&domain=cdn.example.com");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");
var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

```php
<?php
$ch = curl_init('https://api.sirv.com/v2/account/custom-domain?alias=my-account&domain=cdn.example.com');
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => 'DELETE',
  CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'],
  CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);
```

```go
package main

import (
  "fmt"
  "io"
  "net/http"
)

func main() {
  req, _ := http.NewRequest("DELETE", "https://api.sirv.com/v2/account/custom-domain?alias=my-account&domain=cdn.example.com", nil)
  req.Header.Set("authorization", "Bearer BEARER_TOKEN")
  res, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer res.Body.Close()
  out, _ := io.ReadAll(res.Body)
  fmt.Println(res.Status, string(out))
}
```

```ruby
require 'net/http'

uri = URI('https://api.sirv.com/v2/account/custom-domain?alias=my-account&domain=cdn.example.com')
req = Net::HTTP::Delete.new(uri)
req['authorization'] = 'Bearer BEARER_TOKEN'
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts res.code, res.body
```

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/account/custom-domain?alias=my-account&domain=cdn.example.com")!)
request.httpMethod = "DELETE"
request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")
let (data, response) = try await URLSession.shared.data(for: request)
print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))
```

Response

HTTP 200 with an empty body when the command succeeds.
