# Cloudflare Challenge, Turnstile

## Create Task

### **Request Structure**

<table><thead><tr><th width="163">Parameters</th><th width="113">Type</th><th width="124">Required</th><th>Description</th></tr></thead><tbody><tr><td>clientKey</td><td>string</td><td>yes</td><td>Client account key, can be found <a href="https://solvercf.com/dashboard">here</a></td></tr><tr><td>task.type</td><td>string</td><td>yes</td><td>TurnstileTask</td></tr><tr><td>task.websiteUrl</td><td>string</td><td>yes</td><td>Website Url</td></tr><tr><td>task.websiteKey</td><td>string</td><td>yes</td><td>Webiste Key</td></tr><tr><td>task.userAgent</td><td>string</td><td>no</td><td>example: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36</td></tr><tr><td>task.proxy</td><td>string</td><td>no</td><td>example: host:port:user:pass</td></tr></tbody></table>

when captcha is challenge. require additional information

<table><thead><tr><th width="163">Parameters</th><th width="113">Type</th><th width="124">Required</th><th>Description</th></tr></thead><tbody><tr><td>task.pageAction</td><td>string</td><td>yes</td><td>action in page</td></tr><tr><td>task.data</td><td>string</td><td>yes</td><td>data in page</td></tr><tr><td>task.pageData</td><td>string</td><td>yes</td><td>pageData in page</td></tr></tbody></table>

How to get data of challenge.&#x20;

To intercept the required parameters you can inject the following JavaScript on page before the Turnstile widget is loaded. Please reload a few times until you get the data.

```javascript
// inject.js
console.clear = () => console.log('Console was cleared');
const i = setInterval(() => {
  if (window.turnstile) {
    clearInterval(i);
    window.turnstile.render = (a, b) => {
      let params = {
        websiteKey: b.sitekey,
        websiteUrl: window.location.href,
        
        // important
        pageAction: b.action,
        data: b.cData,
        pageData: b.chlPageData,
        
        userAgent: navigator.userAgent
      };
      // we will intercept the message in puppeeter
      console.log('intercepted-params:' + JSON.stringify(params));
      window.cfCallback = b.callback;
      return;
    };
  }
}, 50);
```

### Example request

```
METHOD: POST
```

```http
curl --location 'https://solvercf.com/token/extension/createTask' \
--header 'Content-Type: application/json' \
--data '{
    "clientKey": "0158808f-4fb8-4277-848f-3c74a5249c49", // input your clientKey
    "task": {
        "type": "TurnstileTask",
        "websiteUrl": "http://tsmanaged.zlsupport.com/",
        "websiteKey": "0x4AAAAAAABUYP0XeMJF0xoy"
    }
}'
```

### Example response

| Status  | Explain             |
| ------- | ------------------- |
| created | create task success |
| falied  | create task failed  |

```json
{
    "taskId": "8f31dabc-f7c8-4b6d-857a-94b15acec04b",
    "errorId": 0,
    "errorCode": null,
    "errorDescription": null,
    "status": "created" // change create => created
}
```

## Result Task

### **Request Structure**

<table><thead><tr><th width="135">Parameters</th><th width="117">Type</th><th width="125">Required</th><th>Description</th></tr></thead><tbody><tr><td>clientKey</td><td>string</td><td>yes</td><td>Client account key, can be found <a href="https://solvercf.com/dashboard">here</a></td></tr><tr><td>taskId</td><td>string</td><td>yes</td><td>task id from create task</td></tr></tbody></table>

### Example request

```
METHOD: POST
```

```http
curl --location 'https://solvercf.com/token/extension/getTaskResult' \
--header 'Content-Type: application/json' \
--data '{
    "clientKey": "0158808f-4fb8-4277-848f-3c74a5249c49",
    "taskId": "8f31dabc-f7c8-4b6d-857a-94b15acec04b"
}'
```

### Example response

| Status     | Explain                             |
| ---------- | ----------------------------------- |
| created    | task is created, but not processing |
| processing | task is processing solve            |
| ready      | task solved                         |
| expired    | task is expired                     |
| failed     | task is failed solve                |

```json
{
    "taskId": "8f31dabc-f7c8-4b6d-857a-94b15acec04b",
    "solution": {
        "type": "TurnstileTask",
        "token": "0.DKFXjsiyUD8R1Cv-g4k_XAJgL283BOhVo8LeoQ4v0sseqeMOXS0oyLS-D76zMnDXuQvwPbGtGG-lrBjH-C64wNIUtgbV-VLhR7T4pr85v1bRIxjj11iOeloaTUJ6MqSKNagpvI_KSV7WaB_ePwZt_Ep8Fc3_Gbiju_8mqVqbrueraP1aOXj8gdbV8ugSYc-xEdDF6AtVauamtiN-yOJNNioRF6TEt68zI4H1GwFFg8gGNST8m0Ga4hlr8rf1uO9gR8_PRH9Z9pzlfOLrfsgSKvEZa-8W_XTp5-AIqPvj0JnsnoxaQ50YHCHZ4v0j2lJ1bRXZD_FxOBmy6bB7VYhEequoZqVWbIxv8rMwbFhdUwYZ6x93brV-2i9kl_XC7VMSklQzNmY6jPI99Dfs72ee6rh_izqcV0jJVLD--454tOuFB5kcd9H62w175Sea3519PgWqDi35ANhkew3hwLfQ7Znc18M_5tln7rGRgzvfi7RPUzI65H7XNs8Rs6hFK867zA2b9Osv8Jz-jXwQ-6SQbMZHw0CiAx3rZ9XXBSKBZK-bB4leV1aLcVnzdgUIWEM866nl4oUcneCRtPX6pHNDPxyvu7jUu_xm_clHcULUKhcjLkb4qbUvTpTKR9SldvlAWWZdG8Fn30wyLBy3jYNOWu6pLsVTYyyg6MbNU3SWr5tpejcs8w4ZDQ97PQVM9AZWzPY8zl6HdK-QVXx_RCs34TIuKd3tIol5fI1gIfmlZVCMcNVlZZnbEu1JvmbC23w6USMsgfLqDJ19ARuQUp9n3mlafxOgrOPqas7FBLyPHsatVdMQte1JYf6JdUY2XLMk2Nx99ZCe7ZI5AnN626500nUs-cCipJnjyTtcBwu8WpfK9YWvczNb98dVLEdkWuBZ6DaYZTRvQdk-rJR5dmEPY1qY1cYJJC_3T626nWFD4q8.VEq3b1YceURNdYVxuKJmvw.0250b8270e622ccd5ad5a1f346ec8aa0f07c54b870099708aac61decc96a78ec",
        "cookie": null,
        "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36"
    },
    "cost": 0.0011,
    "status": "ready", // created, processing, ready, expired, failed
    "errorId": 0,
    "errorCode": null,
    "errorDescription": null
}
```

## Example Python

### Create Task

```python
import requests
import json

url = "https://solvercf.com/token/extension/createTask"

payload = json.dumps({
  "clientKey": "0158808f-4fb8-4277-848f-3c74a5249c49",
  "task":{
    "type": "TurnstileTask",
    "websiteUrl": "http://tsmanaged.zlsupport.com/",
    "websiteKey": "0x4AAAAAAABUYP0XeMJF0xoy"
  }  
})
headers = {
  'Content-Type': 'application/json',
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

### Result Task

```python
import requests
import json

url = "https://solvercf.com/token/extension/getTaskResult"

payload = json.dumps({
  "clientKey": "0158808f-4fb8-4277-848f-3c74a5249c49",
  "taskId": "87ffb726-1447-4b48-babe-1326363553b3"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

## Example Nodejs

### Create Task

```javascript
const axios = require('axios');
let data = JSON.stringify({
  "clientKey": "0158808f-4fb8-4277-848f-3c74a5249c49",
  "task":{
    "type": "TurnstileTask",
    "websiteUrl": "http://tsmanaged.zlsupport.com/",
    "websiteKey": "0x4AAAAAAABUYP0XeMJF0xoy"
  }
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://solvercf.com/token/extension/createTask',
  headers: { 
    'Content-Type': 'application/json',
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});
```

### Result Task

```javascript
const axios = require('axios');
let data = JSON.stringify({
  "clientKey": "0158808f-4fb8-4277-848f-3c74a5249c49",
  "taskId": "87ffb726-1447-4b48-babe-1326363553b3"
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://solvercf.com/token/extension/getTaskResult',
  headers: { 
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nguyens-organization-105.gitbook.io/solvercf.com/solver-cloudflare/api-reference/cloudflare-challenge-turnstile.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
