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

# Validate QR Code Info Data

> Validate QR Code info data before creating or updating a QR Code. Ensures the JSON payload structure and content are correct and prevents landing page or data errors. Authentication required via API key.

## Purpose

Use this endpoint to **validate QR Code data before creation**.\
It checks that the `category` and `info` parameters match expected JSON structure for that QR type (e.g., URL, Social Media, Business Card, etc.).

This helps catch issues like:

* Missing required fields
* Invalid URLs
* Wrong `type` values
* Malformed JSON strings

## Request Body (Form Data)

| Field      | Type   | Required | Description            | Example                                             |
| ---------- | ------ | -------- | ---------------------- | --------------------------------------------------- |
| `category` | string | Yes      | QR code category ID    | `1`                                                 |
| `info`     | string | Yes      | QR code info JSON data | `{"type":"url","data":{"url":"http://google.com"}}` |

## Examples

### Validate Website URL QR Code Data

```bash theme={null}
curl -X POST "https://management.scanova.io/qr/validate-info/" \
  -H "Authorization: YOUR_API_KEY" \
  -F "category=1" \
  -F "info={\"type\":\"url\",\"data\":{\"url\":\"https://example.com\"}}"
```

### Validate Social Media QR Code Data

```bash theme={null}
curl -X POST "https://management.scanova.io/qr/validate-info/" \
  -H "Authorization: YOUR_API_KEY" \
  -F "category=15" \
  -F "info={\"type\":\"sMedia\",\"data\":{\"facebook\":\"https://facebook.com/example\",\"instagram\":\"https://instagram.com/example\"}}"
```

### Validate Business Card QR Code Data

```bash theme={null}
curl -X POST "https://management.scanova.io/qr/validate-info/" \
  -H "Authorization: YOUR_API_KEY" \
  -F "category=24" \
  -F "info={\"type\":\"businessCard\",\"data\":{\"name\":\"John Doe\",\"email\":\"john@example.com\",\"phone\":\"+1234567890\"}}"
```

### Validate Event QR Code Data

```bash theme={null}
curl -X POST "https://management.scanova.io/qr/validate-info/" \
  -H "Authorization: YOUR_API_KEY" \
  -F "category=20" \
  -F "info={\"type\":\"event\",\"data\":{\"title\":\"Tech Conference 2025\",\"date\":\"2025-06-15\",\"location\":\"Convention Center\"}}"
```

### **Successful Response (200)**

If the provided data is valid, the API returns a simple success message:

```json theme={null}
"valid"
```

**HTTP Status:** `200 OK`

### **Error Responses**

### `400 Bad Request` — Invalid Data

The `info` object failed validation.\
Common issues include missing fields, invalid `type`, or incorrect data formats.

**Example - Invalid Type Values**

```json theme={null}
{
  "info": [
    "'invalid_type' is not one of ['url', 'email', 'phone', 'text']"
  ]
}
```

**Example - Missing Required Fields**

```json theme={null}
{
  "info": [
    "This field is required."
  ]
}
```

**Example - Invalid URL Format**

```json theme={null}
{
  "info": [
    "Enter a valid URL."
  ]
}
```

**Example - Invalid Email Format**

```json theme={null}
{
  "info": [
    "Enter a valid email address."
  ]
}
```

**Example - Invalid Phone Format**

```json theme={null}
{
  "info": [
    "Enter a valid phone number."
  ]
}
```

## Integration Examples

### **JavaScript Form Validation**

```javascript theme={null}
async function validateQRCodeData(category, infoData) {
  try {
    const formData = new FormData();
    formData.append('category', category);
    formData.append('info', JSON.stringify(infoData));
    
    const response = await fetch('https://management.scanova.io/qr/validate-info/', {
      method: 'POST',
      headers: {
        'Authorization': 'YOUR_API_KEY'
      },
      body: formData
    });
    
    if (response.ok) {
      const result = await response.text();
      if (result === '"valid"') {
        return { valid: true, message: 'Data is valid' };
      }
    } else {
      const error = await response.json();
      return { valid: false, message: error.info[0] };
    }
  } catch (error) {
    return { valid: false, message: 'Validation failed' };
  }
}

// Usage
const result = await validateQRCodeData(1, {
  type: 'url',
  data: { url: 'https://example.com' }
});

if (result.valid) {
  // Proceed with QR code creation
  console.log('Data is valid, creating QR code...');
} else {
  // Show error to user
  console.error('Validation error:', result.message);
}
```

### **Python Validation**

```python theme={null}
import requests
import json

def validate_qr_code_data(category, info_data):
    url = "https://management.scanova.io/qr/validate-info/"
    headers = {"Authorization": "YOUR_API_KEY"}
    
    data = {
        'category': str(category),
        'info': json.dumps(info_data)
    }
    
    try:
        response = requests.post(url, headers=headers, data=data)
        
        if response.status_code == 200:
            result = response.text.strip('"')
            if result == 'valid':
                return {"valid": True, "message": "Data is valid"}
        elif response.status_code == 400:
            error_data = response.json()
            return {"valid": False, "message": error_data['info'][0]}
        
        return {"valid": False, "message": "Validation failed"}
        
    except Exception as e:
        return {"valid": False, "message": f"Error: {str(e)}"}

# Usage
result = validate_qr_code_data(1, {
    "type": "url",
    "data": {"url": "https://example.com"}
})

if result["valid"]:
    print("Data is valid, creating QR code...")
else:
    print(f"Validation error: {result['message']}")
```

### **PHP Validation**

```php theme={null}
<?php
function validateQRCodeData($category, $infoData) {
    $url = "https://management.scanova.io/qr/validate-info/";
    $headers = [
        "Authorization: YOUR_API_KEY"
    ];
    
    $data = [
        'category' => (string)$category,
        'info' => json_encode($infoData)
    ];
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($httpCode === 200) {
        $result = trim($response, '"');
        if ($result === 'valid') {
            return ["valid" => true, "message" => "Data is valid"];
        }
    } elseif ($httpCode === 400) {
        $errorData = json_decode($response, true);
        return ["valid" => false, "message" => $errorData['info'][0]];
    }
    
    return ["valid" => false, "message" => "Validation failed"];
}

// Usage
$result = validateQRCodeData(1, [
    "type" => "url",
    "data" => ["url" => "https://example.com"]
]);

if ($result["valid"]) {
    echo "Data is valid, creating QR code...";
} else {
    echo "Validation error: " . $result["message"];
}
?>
```

## **Notes & Best Practices**

* Always validate before creating or updating dynamic QR Codes — this ensures error-free QR landing pages.
* The validation engine mimics internal creation logic, so a passing validation guarantees successful QR creation (if unchanged).
* Recommended especially when:
  * Building integrations that generate multiple QR codes in bulk
  * Accepting user-provided input through a form or external data source
* Use this endpoint in your **pre-deployment QA pipeline** to validate `info` templates for all categories.


## OpenAPI

````yaml POST /qr/validate-info/
openapi: 3.1.0
info:
  title: Scanova QR Code API
  description: QR Code management endpoints for creating, updating, and managing QR codes
  version: 1.0.0
servers:
  - url: https://management.scanova.io
    description: Production server
security:
  - apiKeyAuth: []
paths:
  /qr/validate-info/:
    post:
      tags:
        - QR Code
      summary: Validate QR Code Info Data
      description: >-
        Validates QR code info data before creating or updating a QR code to
        ensure the landing page will not be broken. This endpoint helps prevent
        errors by validating the JSON payload structure and content before
        actual QR code creation. Requires authentication.
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - category
                - info
              properties:
                category:
                  type: string
                  description: QR code category ID
                  example: '1'
                info:
                  type: string
                  description: QR code info JSON data
                  example: '{"type":"url","data":{"url":"http://google.com"}}'
            examples:
              url_validation:
                summary: Validate URL QR code data
                value:
                  category: '1'
                  info: '{"type":"url","data":{"url":"https://example.com"}}'
              social_media_validation:
                summary: Validate social media QR code data
                value:
                  category: '15'
                  info: >-
                    {"type":"sMedia","data":{"facebook":"https://facebook.com/example","instagram":"https://instagram.com/example"}}
              business_card_validation:
                summary: Validate business card QR code data
                value:
                  category: '24'
                  info: >-
                    {"type":"businessCard","data":{"name":"John
                    Doe","email":"john@example.com","phone":"+1234567890"}}
      responses:
        '200':
          description: Valid QR code info data
          content:
            application/json:
              schema:
                type: string
                example: valid
        '400':
          description: Invalid QR code info data
          content:
            application/json:
              schema:
                type: object
                properties:
                  info:
                    type: array
                    items:
                      type: string
                    example:
                      - '''abc'' is not one of [''url'']'
              examples:
                invalid_type:
                  summary: Invalid type value
                  value:
                    info:
                      - >-
                        'invalid_type' is not one of ['url', 'email', 'phone',
                        'text']
                missing_field:
                  summary: Missing required field
                  value:
                    info:
                      - This field is required.
                invalid_url:
                  summary: Invalid URL format
                  value:
                    info:
                      - Enter a valid URL.
        '401':
          description: Unauthorized - Invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthenticationErrorResponse'
      security:
        - apiKeyAuth: []
components:
  schemas:
    AuthenticationErrorResponse:
      type: object
      properties:
        detail:
          type: string
          description: Authentication error message
          example: Invalid token.
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Enter your API key directly in the Authorization
        header.

````