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

# Actualizar Clave de Servicio

PUT https://api.megaport.com/v2/service/key
Content-Type: application/json

Edita los detalles de una clave de servicio.

Los cambios se definen en el cuerpo de la solicitud. El `productId` se devuelve cuando enumeras las claves de servicio.

Solo incluya los parámetros que desea actualizar. Para una clave de servicio, puede actualizar los siguientes parámetros:

- `singleUse` - Determina si la clave de servicio es de un solo uso o de múltiples usos. Los valores válidos son `true` (un solo uso) y `false` (múltiples usos). Con una clave de múltiples usos, el cliente con el que comparte la clave puede solicitar múltiples conexiones utilizando esa clave.
    
- `active` - Determina si la clave de servicio está disponible para su uso. Los valores válidos son `true` si desea que la clave esté disponible de inmediato y `false` si no desea que la clave esté disponible de inmediato.
    
- `validFor` - El rango de fechas para el cual la clave de servicio es válida. Las fechas se ingresan en formato de marca de tiempo UNIX. Puede usar herramientas como [https://www.epochconverter.com/](https://www.epochconverter.com/) o [https://it-tools.tech/date-converter](https://it-tools.tech/date-converter) para determinar el valor correcto a ingresar.

Reference: https://es.megaport.ferndocs.com/es/api-reference/connections/update-service-key

## Servers

- `https://api.megaport.com` (Entorno de producción, default)
- `https://api-staging.megaport.com` (Entorno de pruebas (solo pruebas, se restablece cada 24 horas))

## Request

### Body (application/json)

This endpoint expects an object.

- `active` (boolean, optional)
- `key` (string, optional)
- `productId` (double, optional)
- `singleUse` (boolean, optional)
- `validFor` (V2ServiceKeyPutRequestBodyContentApplicationJsonSchemaValidFor, optional)

## Response

### 200

Actualizar Clave de Servicio / Actualizar Clave de Servicio

- `data` (V2ServiceKeyPutResponsesContentApplicationJsonSchemaData, optional)
- `message` (string, optional)
- `terms` (string, optional)

## Types

### V2ServiceKeyPutRequestBodyContentApplicationJsonSchemaValidFor

- `end` (double, optional)
- `start` (double, optional)

### V2ServiceKeyPutResponsesContentApplicationJsonSchemaData

- `active` (boolean, optional)
- `bEnd` (V2ServiceKeyPutResponsesContentApplicationJsonSchemaDataBEnd, optional)
- `companyId` (double, optional)
- `companyName` (string, optional)
- `companyUid` (string, optional)
- `createDate` (double, optional)
- `description` (any, optional, nullable)
- `expired` (boolean, optional)
- `key` (string, optional)
- `lastUsed` (any, optional, nullable)
- `maxSpeed` (double, optional)
- `preApproved` (any, optional, nullable)
- `productDto` (V2ServiceKeyPutResponsesContentApplicationJsonSchemaDataProductDto, optional)
- `productId` (double, optional)
- `productName` (string, optional)
- `productUid` (string, optional)
- `singleUse` (boolean, optional)
- `valid` (boolean, optional)
- `validFor` (V2ServiceKeyPutResponsesContentApplicationJsonSchemaDataValidFor, optional)
- `vlan` (any, optional, nullable)

### V2ServiceKeyPutResponsesContentApplicationJsonSchemaDataBEnd

### V2ServiceKeyPutResponsesContentApplicationJsonSchemaDataProductDto

- `companyName` (string, optional)
- `companyUid` (string, optional)
- `connectType` (string, optional)
- `diversityZone` (string, optional)
- `locationId` (double, optional)
- `portSpeed` (double, optional)
- `productName` (string, optional)
- `productUid` (string, optional)
- `vxcPermitted` (boolean, optional)

### V2ServiceKeyPutResponsesContentApplicationJsonSchemaDataValidFor

- `end` (double, optional)
- `start` (double, optional)

## Examples

**Request**

```json
{
  "active": true,
  "key": "96cbcd3b-024e-4ea2-9b9f-ebfe5296b979",
  "productId": 74177,
  "singleUse": false,
  "validFor": {
    "end": 1612015200000,
    "start": 1608506197135
  }
}
```

**Response**

```json
{
  "data": {
    "active": true,
    "bEnd": {},
    "companyId": 1153,
    "companyName": "Megaport Lab",
    "companyUid": "160208ae-01e4-4cb9-8d57-03a197bd47a8",
    "createDate": 1738039556254,
    "description": null,
    "expired": true,
    "key": "96cbcd3b-024e-4ea2-9b9f-ebfe5296b979",
    "lastUsed": null,
    "maxSpeed": 10000,
    "preApproved": null,
    "productDto": {
      "companyName": "Megaport Lab",
      "companyUid": "160208ae-01e4-4cb9-8d57-03a197bd47a8",
      "connectType": "DEFAULT",
      "diversityZone": "blue",
      "locationId": 68,
      "portSpeed": 10000,
      "productName": "Example Port",
      "productUid": "73b2a452-9f93-4c45-afa0-887cf7f17e89",
      "vxcPermitted": true
    },
    "productId": 226855,
    "productName": "Example Port",
    "productUid": "73b2a452-9f93-4c45-afa0-887cf7f17e89",
    "singleUse": false,
    "valid": false,
    "validFor": {
      "end": 1612015200000,
      "start": 1608506197135
    },
    "vlan": null
  },
  "message": "Clave de servicio [96cbcd3b-024e-4ea2-9b9f-ebfe5296b979] actualizada",
  "terms": "This data is subject to the Acceptable Use Policy https://www.megaport.com/legal/acceptable-use-policy"
}
```

**SDK Code**

```python
import requests

url = "https://api.megaport.com/v2/service/key"

payload = {
    "active": True,
    "key": "96cbcd3b-024e-4ea2-9b9f-ebfe5296b979",
    "productId": 74177,
    "singleUse": False,
    "validFor": {
        "end": 1612015200000,
        "start": 1608506197135
    }
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'https://api.megaport.com/v2/service/key';
const options = {
  method: 'PUT',
  headers: {'Content-Type': 'application/json'},
  body: '{"active":true,"key":"96cbcd3b-024e-4ea2-9b9f-ebfe5296b979","productId":74177,"singleUse":false,"validFor":{"end":1612015200000,"start":1608506197135}}'
};

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.megaport.com/v2/service/key"

	payload := strings.NewReader("{\n  \"active\": true,\n  \"key\": \"96cbcd3b-024e-4ea2-9b9f-ebfe5296b979\",\n  \"productId\": 74177,\n  \"singleUse\": false,\n  \"validFor\": {\n    \"end\": 1612015200000,\n    \"start\": 1608506197135\n  }\n}")

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

	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.megaport.com/v2/service/key")

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

request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"active\": true,\n  \"key\": \"96cbcd3b-024e-4ea2-9b9f-ebfe5296b979\",\n  \"productId\": 74177,\n  \"singleUse\": false,\n  \"validFor\": {\n    \"end\": 1612015200000,\n    \"start\": 1608506197135\n  }\n}"

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.megaport.com/v2/service/key")
  .header("Content-Type", "application/json")
  .body("{\n  \"active\": true,\n  \"key\": \"96cbcd3b-024e-4ea2-9b9f-ebfe5296b979\",\n  \"productId\": 74177,\n  \"singleUse\": false,\n  \"validFor\": {\n    \"end\": 1612015200000,\n    \"start\": 1608506197135\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.megaport.com/v2/service/key', [
  'body' => '{
  "active": true,
  "key": "96cbcd3b-024e-4ea2-9b9f-ebfe5296b979",
  "productId": 74177,
  "singleUse": false,
  "validFor": {
    "end": 1612015200000,
    "start": 1608506197135
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.megaport.com/v2/service/key");
var request = new RestRequest(Method.PUT);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"active\": true,\n  \"key\": \"96cbcd3b-024e-4ea2-9b9f-ebfe5296b979\",\n  \"productId\": 74177,\n  \"singleUse\": false,\n  \"validFor\": {\n    \"end\": 1612015200000,\n    \"start\": 1608506197135\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "active": true,
  "key": "96cbcd3b-024e-4ea2-9b9f-ebfe5296b979",
  "productId": 74177,
  "singleUse": false,
  "validFor": [
    "end": 1612015200000,
    "start": 1608506197135
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.megaport.com/v2/service/key")! 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()
```