> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.divert.ly/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.divert.ly/_mcp/server.

# Update a target

PUT https://api-dev.divert.ly/v1/domains/{domain_id}/routes/{route_id}/targets/{target_id}
Content-Type: application/json

Changes the destination URL or its targeting rules.

Reference: https://docs.divert.ly/api-reference/divertly-api/targets/update-target

## Authentication

- `Authorization` header (required) — API key credential, sent as `Key <base64(keyId:secret)>`.

## Servers

- `https://api-dev.divert.ly` (Development, default)
- `https://api.divert.ly` (Production)

## Request

### Path parameters

- `domain_id` (string, required)
- `route_id` (string, required)
- `target_id` (string, required)

### Body (application/json)

This endpoint expects a TargetPutObject.

- `description` (string, optional)
- `enabled` (boolean, optional, nullable) — Whether the target may be resolved for the proxy. Omit to leave unchanged.
- `selectorValue` (string, optional)
- `url` (string, optional)
- `weight` (long, optional, nullable) — Relative share for the weighted strategy. 0 removes the target from rotation; omit to leave unchanged.

## Response

### 200

OK

- `body` (Target, optional)

## Errors

### 400 Bad Request Error

Bad Request - malformed or failed validation

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 401 Unauthorized Error

Unauthorized - missing, malformed or rejected credentials

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 403 Forbidden Error

Forbidden - the principal is not permitted to make this request

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 404 Not Found Error

Not Found - no such resource

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 429 Too Many Requests Error

Too Many Requests - per-principal rate limit exceeded

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 500 Internal Server Error

Internal Server Error

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

## Types

### Target

- `createdAt` (datetime, optional)
- `description` (string, optional)
- `enabled` (boolean, optional)
- `id` (string, optional)
- `organizationId` (string, optional)
- `risk` (TargetRisk, optional, nullable)
- `routeId` (string, optional)
- `selectorValue` (string, optional)
- `updatedAt` (datetime, optional)
- `url` (string, optional)
- `weight` (long, optional)

### ErrorResponseMeta

- `errorCode` (enum, optional)
  - Allowed values: `E1000`, `E1001`, `E1002`, `E1003`, `E1010`, `E1020`, `E1030`, `E1035`, `E1036`, `E1040`, `E1060`, `E1070`, `E1080`, `E1082`, `E1083`, `E1090`, `E1100`, `E1110`, `E1120`, `E1130`, `E1140`, `E1150`, `E1160`, `E1170`, `E1171`, `E1180`, `E1190`, `E1200`, `E1210`, `E1220`, `E1230`, `E1231`, `E1240`, `E1250`, `E1260`, `E1270`, `E1280`, `E1290`, `E1300`, `E1310`, `E1320`, `E1325`, `E1330`, `E1335`, `E1340`, `E1350`, `E1360`, `E1365`, `E1370`, `E1380`, `E1390`, `E1395`, `E1400`, `E1410`, `E1420`, `E1430`, `E1440`, `E1450`, `E1460`, `E1470`, `E1480`, `E1490`, `E1500`, `E1510`, `E1520`, `E1530`, `E1540`, `E1550`, `E1560`, `E1570`, `E1571`, `E1580`, `E1590`, `E1600`, `E1610`, `E1620`, `E1630`, `E1636`, `E1640`, `E1650`, `E1660`, `E1670`, `E1680`, `E1690`, `E1700`, `E1710`, `E1720`, `E1730`, `E1740`, `E1750`, `E1800`, `E1801`, `E1802`, `E1810`, `E1820`, `E1830`, `E1850`, `E1900`, `E1950`, `E2000`, `E2100`, `E2110`, `E2120`, `E2130`, `E2140`, `E2150`, `E2160`, `E2170`, `E2180`, `E3190`, `E3200`, `E3210`, `E3220`, `E3230`, `E3240`, `E3250`, `E3300`, `E3310`, `E3400`, `E3410`, `E3420`, `E3430`, `E3440`, `E3450`, `E3460`, `E3470`, `E3480`, `E3490`, `E3510`, `E3520`, `E3530`, `E3540`, `E3550`, `E3560`, `E3570`, `E3580`

### TargetRisk

- `lastCheckedAt` (datetime, optional, nullable)
- `reason` (string, optional, nullable)
- `score` (long, optional)
- `status` (enum, optional)
  - Allowed values: `unknown`, `pending`, `clean`, `flagged`
- `thresholdAtCheck` (long, optional)

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "body": {
    "createdAt": "2024-01-15T09:30:00Z",
    "description": "string",
    "enabled": true,
    "id": "string",
    "organizationId": "string",
    "risk": {
      "lastCheckedAt": "2024-01-15T09:30:00Z",
      "reason": "string",
      "score": 1,
      "status": "unknown",
      "thresholdAtCheck": 1
    },
    "routeId": "string",
    "selectorValue": "string",
    "updatedAt": "2024-01-15T09:30:00Z",
    "url": "string",
    "weight": 1
  }
}
```

**SDK Code**

```python
import requests

url = "https://api-dev.divert.ly/v1/domains/domain_id/routes/route_id/targets/target_id"

payload = {}
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api-dev.divert.ly/v1/domains/domain_id/routes/route_id/targets/target_id';
const options = {
  method: 'PUT',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api-dev.divert.ly/v1/domains/domain_id/routes/route_id/targets/target_id"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("Authorization", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api-dev.divert.ly/v1/domains/domain_id/routes/route_id/targets/target_id")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api-dev.divert.ly/v1/domains/domain_id/routes/route_id/targets/target_id")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api-dev.divert.ly/v1/domains/domain_id/routes/route_id/targets/target_id', [
  'body' => '{}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api-dev.divert.ly/v1/domains/domain_id/routes/route_id/targets/target_id");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api-dev.divert.ly/v1/domains/domain_id/routes/route_id/targets/target_id")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```