> For the complete documentation index, see [llms.txt](https://docs.terragon.io/documents/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.terragon.io/documents/terragon-api-document/twofactor.md).

# TwoFactor

Two-factor authentication

## Initiate 2FA setup

> Initiate two-factor authentication setup

```json
{"openapi":"3.0.0","info":{"title":"Terragon API Document","version":"1.0.0"},"tags":[{"name":"TwoFactor","description":"Two-factor authentication"}],"servers":[{"url":"https://api.terragon.io/player/api","description":"Staging server"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"Error":{"type":"object","properties":{"message":{"type":"string","description":"Error message"}}},"ValidationError":{"type":"object","properties":{"message":{"type":"string","description":"Error message"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}},"description":"Validation errors by field"}}}}},"paths":{"/v1/2fa/initiate":{"post":{"tags":["TwoFactor"],"summary":"Initiate 2FA setup","description":"Initiate two-factor authentication setup","operationId":"initiate2Fa","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type"],"properties":{"type":{"type":"string","enum":["totp","email","sms"],"description":"Type of 2FA method"},"phone":{"type":"string","description":"Phone number (required for SMS)"}}}}}},"responses":{"200":{"description":"2FA setup initiated successfully","content":{"application/json":{"schema":{"type":"object","properties":{"secret":{"type":"string","description":"TOTP secret key (for TOTP method)"},"qr_code":{"type":"string","description":"QR code image URL (for TOTP method)"},"otp_code":{"type":"string","description":"OTP code (for email/SMS methods)"}}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"Validation errors","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}}}}
```

## Enable 2FA

> Enable two-factor authentication

```json
{"openapi":"3.0.0","info":{"title":"Terragon API Document","version":"1.0.0"},"tags":[{"name":"TwoFactor","description":"Two-factor authentication"}],"servers":[{"url":"https://api.terragon.io/player/api","description":"Staging server"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"Error":{"type":"object","properties":{"message":{"type":"string","description":"Error message"}}},"ValidationError":{"type":"object","properties":{"message":{"type":"string","description":"Error message"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}},"description":"Validation errors by field"}}}}},"paths":{"/v1/2fa/enable":{"post":{"tags":["TwoFactor"],"summary":"Enable 2FA","description":"Enable two-factor authentication","operationId":"enable2Fa","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type","otp_code"],"properties":{"type":{"type":"string","enum":["totp","email","sms"],"description":"Type of 2FA method"},"otp_code":{"type":"string","description":"OTP code for verification"}}}}}},"responses":{"200":{"description":"2FA enabled successfully","content":{"application/json":{"schema":{"type":"object","properties":{"enabled":{"type":"boolean"},"type":{"type":"string","enum":["totp","email","sms"]}}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"Validation errors","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}}}}
```

## Disable 2FA

> Disable two-factor authentication

```json
{"openapi":"3.0.0","info":{"title":"Terragon API Document","version":"1.0.0"},"tags":[{"name":"TwoFactor","description":"Two-factor authentication"}],"servers":[{"url":"https://api.terragon.io/player/api","description":"Staging server"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"Error":{"type":"object","properties":{"message":{"type":"string","description":"Error message"}}},"ValidationError":{"type":"object","properties":{"message":{"type":"string","description":"Error message"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}},"description":"Validation errors by field"}}}}},"paths":{"/v1/2fa/disable":{"post":{"tags":["TwoFactor"],"summary":"Disable 2FA","description":"Disable two-factor authentication","operationId":"disable2Fa","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["otp_code"],"properties":{"otp_code":{"type":"string","description":"OTP code for verification"}}}}}},"responses":{"200":{"description":"2FA disabled successfully","content":{"application/json":{"schema":{"type":"object","properties":{"enabled":{"type":"boolean"}}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"Validation errors","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}}}}
```

## Mark 2FA method as preferred

> Set a specific 2FA method as preferred

```json
{"openapi":"3.0.0","info":{"title":"Terragon API Document","version":"1.0.0"},"tags":[{"name":"TwoFactor","description":"Two-factor authentication"}],"servers":[{"url":"https://api.terragon.io/player/api","description":"Staging server"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"Error":{"type":"object","properties":{"message":{"type":"string","description":"Error message"}}},"ValidationError":{"type":"object","properties":{"message":{"type":"string","description":"Error message"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}},"description":"Validation errors by field"}}}}},"paths":{"/v1/2fa/mark-as-preferred":{"post":{"tags":["TwoFactor"],"summary":"Mark 2FA method as preferred","description":"Set a specific 2FA method as preferred","operationId":"markPreferred2Fa","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["type"],"properties":{"type":{"type":"string","enum":["totp","email","sms"],"description":"Type of 2FA method"}}}}}},"responses":{"200":{"description":"2FA method marked as preferred successfully","content":{"application/json":{"schema":{"type":"object","properties":{"preferred_type":{"type":"string","enum":["totp","email","sms"]}}}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"422":{"description":"Validation errors","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}}}}
```
