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

# Integrity

> Each request in this task is priced at only €0.003.

This helper task creates an Integrity token for Twitch actions like following, subscribing, or sending bits. You can also do this with our [Kasada](https://apidocs.salamoonder.com/tasks/kasada) task, this just makes it easier.

## Create Task​

Create the task with the [createTask](https://apidocs.salamoonder.com/endpoint/createTask) endpoint, or use our [Software Development Kit ](https://apidocs.salamoonder.com/sdk/official)to make your integration process even easier!

### Task Structure

| **Property**   | **Type** | **Required** |
| :------------- | :------: | :----------: |
| `access_token` |  String  |      Yes     |
| `device_id`    |  String  |      No      |
| `client_id`    |  String  |      No      |

### **Example Request**

```json theme={null}
POST https://salamoonder.com/api/createTask
Host: salamoonder.com
Content-Type: application/json

{
    "api_key": "YOUR_API_KEY",
    "task": {
        "type": "Twitch_PublicIntegrity",
        "access_token": "your_twitch_account_oauth",
        //"device_id": "K3sKKpQhYQwymZFP6zIcu5LCOxyT24",
		//"client_id": "kimne78kx3ncx6brgo4mv6wki5h1ko"
    }
}
```

Upon successfully submitting the task to us, you should receive a 'taskId' in the response.

### Example Response

```json theme={null}
{
  "error_code": 0,
  "error_description": "",
  "taskId": "d4611a5f-9b4e-4f4a-94a2-8303d97562e1"
}
```

**Response Fields:**

* `taskId` - Unique identifier for this task. Use this to retrieve results.

## **Getting Results**

Retrieve the results using the [getTaskResult ](https://apidocs.salamoonder.com/api/gettaskresult-task-result)method. or use our [Software Development Kit ](https://apidocs.salamoonder.com/sdk/official)to make your integration process even easier!

### **Example Request**

```json theme={null}
POST https://salamoonder.com/api/getTaskResult
Host: salamoonder.com
Content-Type: application/json

{
  "api_key": "YOUR_API_KEY",
  "taskId": "d4611a5f-9b4e-4f4a-94a2-8303d97562e1"
}
```

### Example Response

```json theme={null}
{
   "errorId":0,
   "solution":{
      "device-id":"ba478854e9d42411....",
      "integrity-token":"v4.local.IvusFCEJ6-Srca31_dOMU6WnJRLFy7P-rH_4..",
      "expiration":"1763692850412",
      "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleW..",
      "client-id":"kimne78kx3ncx6brgo4mv6wki5h1ko"
   },
   "status":"ready"
}
```

**Response Fields:**

* `device-id` - Device identifier used for this task
* `integrity-token` - Ready-to-use Twitch integrity token for authentication
* `expiration` - Whenever the token will expire.
* `user-agent` - User-agent that was used to generate the token
* `client-id` - Client ID used for this request

## Quick Start Example

Because this is a helper function, there is no official example available, but we do include quick start code in Python.

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

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://salamoonder.com/api"

ACCESS_TOKEN = ""

# Step 1: Create task
task_data = {
    "api_key": API_KEY,
    "task": {
        "type": "Twitch_PublicIntegrity",
        "access_token": ACCESS_TOKEN,
        #"device_id": "your_device_id",
        #"client_id": "your_client_id"
    }
}

response = requests.post(f"{BASE_URL}/createTask", json=task_data)
task_id = response.json()["taskId"]
print(f"Task created: {task_id}")

# Step 2: Poll for results
while True:
    result_data = {
        "api_key": API_KEY,
        "taskId": task_id
    }
    
    response = requests.post(f"{BASE_URL}/getTaskResult", json=result_data)
    result = response.json()
    
    if result["status"] == "ready":
        token = result["solution"]["integrity-token"]
        user_agent = result["solution"]["user-agent"]
        print(f"Integrity Token: {token}")
        print(f"User-Agent: {user_agent}")
        break
    
    time.sleep(2)
```
