TrustCaptcha API
The TrustCaptcha API is one call from your backend: fetch the result of a verification with the token the widget wrote into your form. Everything before that, creating the verification and solving the challenge, the widget does on its own.
How to judge the result, the recommended score thresholds and the whole flow in your language are in Result Validation.
Fetch a verification result
Section titled “Fetch a verification result”https://api.trustcomponent.com/captcha/v3/verifications/{verificationId}/resultsReturns the result of a verification
Call it from your server with the verification id from the token the widget put into your form. Every refusal that will not change on a retry carries a stable code, so your code can tell a visitor who has not finished from a result that was already retrieved or has expired.
Authentication: API key as bearer token. Operation getResultV3.
# The verification id is the "verificationId" inside the token the widget wrote into your form.curl "https://api.trustcomponent.com/captcha/v3/verifications/<verification_id>/results" \ -H "Authorization: Bearer <your_api_key>"import { TrustComponent } from '@trustcomponent/sdk';
const tc = new TrustComponent('<your_api_key>');
// The token from the form field tc-verification-token.const result = await tc.captcha.getVerificationResult('<verification_token>');use TrustComponent\TrustComponent;
$tc = new TrustComponent('<your_api_key>');
// The token from the form field tc-verification-token.$result = $tc->captcha()->getVerificationResult('<verification_token>');from trustcomponent import TrustComponent
tc = TrustComponent("<your_api_key>")
# The token from the form field tc-verification-token.result = tc.captcha.get_verification_result("<verification_token>")import com.trustcomponent.sdk.TrustComponent;import com.trustcomponent.sdk.model.CaptchaVerificationResult;
TrustComponent tc = new TrustComponent("<your_api_key>");
// The token from the form field tc-verification-token.CaptchaVerificationResult result = tc.captcha().getVerificationResult("<verification_token>");using TrustComponent;
using var tc = new TrustComponentClient("<your_api_key>");
// The token from the form field tc-verification-token.var result = await tc.Captcha.GetVerificationResultAsync("<verification_token>");import ( "context"
"github.com/trustcomponent/trustcomponent-go")
tc := trustcomponent.New("<your_api_key>")
// The token from the form field tc-verification-token.result, err := tc.Captcha.GetVerificationResult(context.Background(), "<verification_token>")if err != nil { panic(err)}require 'trustcomponent'
tc = TrustComponent::Client.new('<your_api_key>')
# The token from the form field tc-verification-token.result = tc.captcha.get_verification_result('<verification_token>')let tc = trustcomponent::TrustComponent::new("<your_api_key>");
// The token from the form field tc-verification-token.let result = tc.captcha.get_verification_result("<verification_token>").await?;{ "captchaId": "cc2e2d5e-d1ef-4a7f-a7bd-dec5b37df47a", "verificationId": "cc2e2d5e-d1ef-4a7f-a7bd-dec5b37df47a", "isVerificationPassed": true, "score": 0.3, "decisionType": "STANDARD", "decisionAction": "ALLOW", "isGatewayFailoverActive": false, "isRiskScoringEnabled": true, "isMinimalDataModeEnabled": false, "origin": "https://www.example.com", "ipAddress": "203.0.113.7", "countryCode": "DE", "deviceFamily": "Mac", "operatingSystem": "Mac OS X", "browser": "Firefox", "verificationStartedAt": "2020-01-01T13:30:05.941Z", "verificationFinishedAt": "2020-01-01T13:30:09.512Z", "resultExpiresAt": "2020-01-01T13:45:09.512Z", "resultFirstFetchedAt": "2020-01-01T13:30:10.106Z", "resultLastFetchedAt": "2020-01-01T13:30:10.106Z"}Path parameters
| Name | Type | Description |
|---|---|---|
verificationIdrequired | string (uuid) | ID of a verification |
Query parameters
| Name | Type | Description |
|---|---|---|
clientFailoveroptional | boolean | Set when the widget could not reach TrustCaptcha (clientFailover in its token). The public gateway then answers on its own and lets the visitor pass only while it has seen an outage itself. |
Response 200 · application/json
| Field | Type | Description |
|---|---|---|
captchaId | string (uuid) | Id of the captcha (in the dashboard) the verification ran on. |
verificationId | string (uuid) | Id of the verification, the one from the token. |
isVerificationPassed | boolean | Whether the visitor passed the CAPTCHA. The field most integrations act on. |
score | number | Risk that the request is automated, from 0 (probably human) to 1 (probably automated). · 0 to 1 |
decisionType | string | How the verification outcome was determined. Possible values include STANDARD, BYPASS_KEY, CUSTOM_ACCESS_RULE, GLOBAL_IP_ACCESS_RULE, FAILOVER, FAILOVER_TOLERANCE. |
decisionAction | string | The recommended action for this verification. Possible values include NO_ACTION, ALLOW, BLOCK, CUSTOM. |
isGatewayFailoverActive | boolean | True when the gateway synthesized this result because the captcha service was unreachable. |
isRiskScoringEnabled | boolean | Whether the risk analysis of the captcha was switched on for this verification. |
isMinimalDataModeEnabled | boolean | Whether the captcha runs in minimal data mode; then origin, IP address and device fields are empty. |
origin | string | Origin of the page the widget ran on. |
ipAddress | string | IP address of the visitor. |
countryCode | string | Two-letter ISO 3166-1 alpha-2 country code derived from the client IP. Empty string if not resolvable. |
deviceFamily | string | Device family of the visitor, from the user agent. |
operatingSystem | string | Operating system of the visitor, from the user agent. |
browser | string | Browser of the visitor, from the user agent. |
verificationStartedAt | string | When the widget started the verification. |
verificationFinishedAt | string | When the visitor finished the verification. |
resultExpiresAt | string | Until when the result can be retrieved. |
resultFirstFetchedAtmay be null | string | When the result was retrieved for the first time. |
resultLastFetchedAtmay be null | string | When the result was retrieved for the last time. |
Status codes
| Status | Meaning |
|---|---|
200 | Result object |
401 | API key missing (code: credentials_missing) or invalid (code: credentials_invalid) |
403 | The API key has no access to the project of this verification (code: access_denied) |
404 | No verification with this id |
409 | The visitor has not finished the verification yet (code: result_not_released) |
410 | The result can no longer be retrieved: its retrieval limit is reached (code: result_retrieval_limit_reached) or it has expired (code: result_expired) |
412 | Client failover claimed, but no recent outage is on record (code: client_failover_rejected) |
429 | Too many requests (code: rate_limit_exceeded); retry after the seconds in Retry-After |
The SDKs take the whole token and read the verification id and the clientFailover flag from it. With cURL, decode the token (Base64 of JSON) and send both yourself; see The verification token.
Retrieval rules
Section titled “Retrieval rules”- A result can be retrieved for 15 minutes after the verification, so fetch it when the form arrives.
- By default it can be retrieved once; a second fetch answers
410withcode: result_retrieval_limit_reached. Validity and the number of retrievals can be changed per captcha environment. - While the visitor has not finished, the answer is
409withcode: result_not_released.
Failover
Section titled “Failover”When the widget cannot reach TrustCaptcha, its token says so, and the public gateway decides on its own whether the visitor may pass: only while it has seen the outage itself. A token that claims a failover the gateway has not seen answers 412 with code: client_failover_rejected. What your backend should do in each case is in Failover Behavior.
Test verification ids
Section titled “Test verification ids”These verification ids answer with a fixed result, without a real verification, with any API key of a project that has TrustCaptcha. The last digit picks the answer:
verificationId | Answer |
|---|---|
00000000-0000-0000-0000-000000000000 | 200 with a passed sample result |
00000000-0000-0000-0000-000000000001 | 404 |
00000000-0000-0000-0000-000000000002 | 409, code: result_not_released |
00000000-0000-0000-0000-000000000003 | 410, code: result_expired |
00000000-0000-0000-0000-000000000004 | 410, code: result_retrieval_limit_reached |
To try the SDK examples above, use the token eyJ2ZXJpZmljYXRpb25JZCI6IjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMCJ9 as <verification_token>: it carries the first of them.