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

# Validate Referral Code

GET https://driver/#get16

# Validate Referral Code

A public endpoint to check whether a referral code is valid prior to registration or sign-in. Searches across both users and drivers databases, and returns the referrer type (`USER` or `DRIVER`) with a privacy-masked referrer name.

***

### Endpoint Overview

* **Method:** `POST`

* **Route:** `/api/v1/referral/validate`

* **Authentication:** `None (Public)`

* **Content-Type:** `application/json`

***

### Request Headers

| Header         | Type     | Required | Description                |
| -------------- | -------- | -------- | -------------------------- |
| `Content-Type` | `string` | **Yes**  | Must be `application/json` |

***

### Request Body Schema

| Field           | Data Type | Required | Default | Allowed Values / Constraints                     | Description               |
| --------------- | --------- | -------- | ------- | ------------------------------------------------ | ------------------------- |
| `referral_code` | `string`  | **Yes**  | —       | Min length 1 (e.g. `"CAP_8X9K2"`, `"USR_1A2B3"`) | Referral code to validate |

#### Example Request Body

```json
{
  "referral_code": "CAP_8X9K2"
}

```

***

### Response Body Schema (`200 OK`)

| Field           | Data Type | Optional | Allowed Values / Constraints | Description                                      |
| --------------- | --------- | -------- | ---------------------------- | ------------------------------------------------ |
| `valid`         | `boolean` | No       | `true`, `false`              | Whether the referral code is active and exists   |
| `referrer_type` | `enum`    | Yes      | `"USER"`, `"DRIVER"`         | Platform role of code owner (omitted if invalid) |
| `referrer_name` | `string`  | Yes      | Masked string or `null`      | Masked name for privacy (e.g. `"Ravi K**\*"`)    |

***

### Response Examples

#### 1. `200 OK` — Valid Driver Referral Code

```json
{
  "valid": true,
  "referrer_type": "DRIVER",
  "referrer_name": "Ravi K***"
}

```

#### 2. `200 OK` — Valid User Referral Code

```json
{
  "valid": true,
  "referrer_type": "USER",
  "referrer_name": "Ananya S***"
}

```

#### 3. `200 OK` — Invalid / Non-Existent Referral Code

```json
{
  "valid": false
}

```

#### 4. `400 Bad Request` — Validation Error (Missing `referral_code`)

```json
{
  "success": false,
  "message": "Validation failed: referral_code: Referral code is required",
  "errors": [
    {
      "field": "referral_code",
      "message": "Referral code is required"
    }
  ]
}

```

#### 5. `500 Internal Server Error`

```json
{
  "error": "Failed to validate referral code"
}

```

***

### Status Codes Reference

| HTTP Status Code                | Condition                                                              |
| ------------------------------- | ---------------------------------------------------------------------- |
| **`200 OK`**                    | Code validated successfully (returns `valid: true` or `valid: false`). |
| **`400 Bad Request`**           | Missing or empty `referral_code` in request body.                      |
| **`500 Internal Server Error`** | Server or database lookup error.                                       |

Reference: https://docs.driver.olycab.in/oly-driver/referal/validate-referral-code

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Examples

**SDK Code**

```python
import requests

url = "https://driver/#get16"

headers = {"Authorization": "Bearer <token>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://driver/#get16';
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

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"
	"net/http"
	"io"
)

func main() {

	url := "https://driver/#get16"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	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://driver/#get16")

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'

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.get("https://driver/#get16")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://driver/#get16', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://driver/#get16");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://driver/#get16")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

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()
```