> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wavix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate SMS and Voice 2FA via API

> Developer guide for implementing secure verification using the Wavix 2FA API.

Once you have created a [2FA Service](/messaging/2fa-setup), use the methods below to implement the verification flow in your application.

## Send a verification code

To send a code, [create a Verification](/api-reference/2fa/create-a-2fa-verification). Wavix automatically generates and sends the OTP.

```http theme={null}
POST https://api.wavix.com/v1/two-fa/verification
Authorization: Bearer your_api_key
Content-Type: application/json
```

**Request body:**

```json theme={null}
{
   "service_id": "7204a030201211ee9fb47d093f2f127c",
   "to": "37128782931",
   "channel": "sms"
}
```

* `service_id`: The unique ID of your 2FA Service.
* `to`: The destination phone number in E.164 format.
* `channel`: Use `sms` or `voice`.

**Response example:**

```json theme={null}
{
   "success": true,
   "service_id": "7204a030201211ee9fb47d093f2f127c",
   "destination": "37128782931",
   "session_id": "5f1a8680201511eeafdfcfc3dedfac51",
   "created_at": "2023-07-11T18:04:25.786Z",
   "number_lookup": {
      "number_type": "mobile",
      "country": "LV",
      "current_carrier": "Latvijas Mobilais Telefons"
   }
}
```

* `session_id`: Use this ID to validate the OTP or resend the code.
* `number_lookup`: Returned only if **Number validation** is enabled for the service.

## Resend a verification code

If a user doesn't receive the initial code or you want to try a different delivery method, use the [resend method](/api-reference/2fa/resend-a-code). While Wavix supports automatic channel failover, this method gives you manual control to resend a code via a specific `channel` (`sms` or `voice`).

```http theme={null}
POST https://api.wavix.com/v1/two-fa/verification/{session_id}
Authorization: Bearer your_api_key
Content-Type: application/json
```

**Request body:**

```json theme={null}
{
   "channel": "voice"
}
```

## Validate an OTP

In order to [validate an OTP](/api-reference/2fa/validate-a-code) entered by a user, use the method below:

```http theme={null}
POST https://api.wavix.com/v1/two-fa/verification/{session_id}/check
Authorization: Bearer your_api_key
Content-Type: application/json
```

**Request body:**

```json theme={null}
{
   "code": "749503"
}
```

**Response:**

```json theme={null}
{
    "is_valid": true
}
```

## Additional operations

### Cancel a Verification

You can [cancel a Verification](/api-reference/2fa/cancel-a-2fa-verification) to invalidate all codes and prevent further resends.

```http theme={null}
PATCH https://api.wavix.com/v1/two-fa/verification/{session_id}/cancel
Authorization: Bearer your_api_key
```

### Query service logs

Retrieve [active Verifications](/api-reference/2fa/list-2fa-verifications) and their associated events.

```http theme={null}
GET https://api.wavix.com/v1/two-fa/service/{service_id}/sessions?from=2023-07-01&to=2023-07-31
Authorization: Bearer your_api_key
```

To see [specific events](/api-reference/2fa/list-2fa-verification-events) for a session:

```http theme={null}
GET https://api.wavix.com/v1/two-fa/session/{session_id}/events
Authorization: Bearer your_api_key
```

**Event types:**

* `Number lookup`: Wavix checked if the destination number is valid.
* `Code sent via SMS`: OTP sent via text.
* `Code sent via voice`: OTP sent via automated call.
* `Verification`: A code validation attempt.
