> This page is for Developers.

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

# Activate MFA key

PATCH https://iot.telia.lt/api/v1/user/mfa/{key_id}
Content-Type: application/json

Activates a pending MFA key for the authenticated user.

After you [create an MFA key](/developers/api/authentication/post-mfa), the key has status `Activation Pending`.
To complete setup, call this endpoint with the MFA key ID and a valid 6-digit time-based one-time password (TOTP) generated from the `secret_key` or `otpauth` URI returned during creation.

Once activated, the MFA key status changes to `Active`, and MFA is enforced on subsequent logins with [user credentials](/developers/auth/user-credentials).

For more information, see [Multi-factor authentication](/developers/auth/multi-factor-authentication).


Reference: https://docs.iot.telia.lt/developers/api/authentication/user-mfa-by-id-patch

## Authentication

- `Authorization` header (bearer token, required) — An `auth_token` should be provided to authenticate a session. To obtain an `auth_token`, see the [`/api/v1/authenticate` **POST** request](/developers/api/authentication/authenticate).

## Request

### Path parameters

- `key_id` (integer, required) — The unique identifier of the MFA key to activate. This ID is returned when you [create the MFA key](/developers/api/authentication/post-mfa).

### Body (application/json)

This endpoint expects an object.

- `status` (ApiV1UserMfaKeyIdPatchRequestBodyContentApplicationJsonSchemaStatus, required) — The target status for the MFA key.
- `code` (string, required) — The 6-digit TOTP code generated by your authenticator app using the `secret_key` or `otpauth` URI from the MFA key creation response. This code changes every 30 seconds.

## Response

### 204

MFA key activated successfully. No content returned.

## Errors

### 404 Not Found Error

MFA key not found. Verify the `key_id` is correct and belongs to the authenticated user.

- `error_code` (integer, optional) — Numeric error code for programmatic handling.
- `error_token` (string, optional) — String identifier for the error type.
- `message` (string, optional) — Human-readable error message.

### 409 Conflict Error

MFA key is already activated. Each key can only be activated once.

- `error_code` (integer, optional) — Numeric error code for programmatic handling.
- `error_token` (string, optional) — String identifier for the error type.
- `message` (string, optional) — Human-readable error message.

### 422 Unprocessable Entity Error

Invalid TOTP code. The code didn't match the expected value. This can happen if: - The code was entered incorrectly - The code expired (codes are valid for 30 seconds) - The device clock is out of sync with the server

- `error_code` (integer, optional) — Numeric error code for programmatic handling.
- `error_token` (string, optional) — String identifier for the error type.
- `message` (string, optional) — Human-readable error message.

## Types

### ApiV1UserMfaKeyIdPatchRequestBodyContentApplicationJsonSchemaStatus

The target status for the MFA key.

- `id` (integer, required) — Status ID. Use `1` to activate the key. You can retrieve available status IDs from [List MFA key statuses](/developers/api/authentication/user-mfa-status-get).

## Examples

**Request**

```json
{
  "status": {
    "id": 1
  },
  "code": "123456"
}
```

**SDK Code**

```python Authentication_UserMfaByIdPatch_example
import requests

url = "https://iot.telia.lt/api/v1/user/mfa/1"

payload = {
    "status": { "id": 1 },
    "code": "123456"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Authentication_UserMfaByIdPatch_example
const url = 'https://iot.telia.lt/api/v1/user/mfa/1';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"status":{"id":1},"code":"123456"}'
};

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

```go Authentication_UserMfaByIdPatch_example
package main

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

func main() {

	url := "https://iot.telia.lt/api/v1/user/mfa/1"

	payload := strings.NewReader("{\n  \"status\": {\n    \"id\": 1\n  },\n  \"code\": \"123456\"\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	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 Authentication_UserMfaByIdPatch_example
require 'uri'
require 'net/http'

url = URI("https://iot.telia.lt/api/v1/user/mfa/1")

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

request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"status\": {\n    \"id\": 1\n  },\n  \"code\": \"123456\"\n}"

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

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

HttpResponse<String> response = Unirest.patch("https://iot.telia.lt/api/v1/user/mfa/1")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"status\": {\n    \"id\": 1\n  },\n  \"code\": \"123456\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://iot.telia.lt/api/v1/user/mfa/1', [
  'body' => '{
  "status": {
    "id": 1
  },
  "code": "123456"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Authentication_UserMfaByIdPatch_example
using RestSharp;

var client = new RestClient("https://iot.telia.lt/api/v1/user/mfa/1");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"status\": {\n    \"id\": 1\n  },\n  \"code\": \"123456\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Authentication_UserMfaByIdPatch_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "status": ["id": 1],
  "code": "123456"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://iot.telia.lt/api/v1/user/mfa/1")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
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()
```