Skip to main content

Trigger a Visual Scan Manually

Trigger a scan manually using the Visual scanner API.

Using the Visual scanner API, you can execute Visual scanner builds on-demand, allowing immediate checks and faster response times to visual discrepancies. This API provides the following benefits:

  • Automated Workflows: Businesses can ensure visual inspections are part of their regular development cycles by integrating the Visual scanner API into automated workflows, such as CI/CD pipelines. The API automatically triggers a scan whenever there is an update or change to the codebase. This ensures continuous integration and delivery without manual intervention.

  • Flexibility and Control: This API allows developers to trigger scans based on specific events or conditions rather than predefined schedules. For example, a visual scan can be triggered immediately after deployment or during off-peak hours to minimize performance impact.

  • Scalability: When managing multiple websites or larger projects, triggering scans via API can help manage scans across multiple environments and URLs efficiently. The scalability of the solution ensures that performance and visual consistency remain consistent even when the project grows.

  • Integration with Other Tools: You can integrate build triggers and APIs with other tools and systems, such as issue tracking systems, internal notification systems, etc. This makes it possible to automatically report any detected issues to the relevant team members and resolve them as soon as possible.

Make sure your $PERCY_TOKEN is a Write-only or Full-access token.

Request

To trigger a visual scan using the Visual scanner API, use the following command where YOUR_PERCY_TOKEN is your PERCY_TOKEN present in the Project settings.

Copy icon Copy snippet

The following code snippets show examples of the API request in Python, JavaScript, and Java:

import requests

# Replace 'your_token_here' with your actual Percy token
PERCY_TOKEN = 'your_token_here'

url = 'https://percy.io/api/v1/visual-scanner-builds'
headers = {
    'Authorization': f'Token token={PERCY_TOKEN}'
}

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

# Printing the response
print(response.text)
const fetch = require('node-fetch');

const percyToken = 'your_token_here'; // Replace with your actual Percy token

const url = 'https://percy.io/api/v1/visual-scanner-builds';
const headers = {
    'Authorization': `Token token=${percyToken}`
};

fetch(url, {
    method: 'POST',
    headers: headers
})
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpHeaders;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        String percyToken = "your_token_here"; // Replace with your actual Percy token

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://percy.io/api/v1/visual-scanner-builds"))
                .header("Authorization", "Token token=" + percyToken)
                .POST(HttpRequest.BodyPublishers.noBody())
                .build();

        try {
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
            System.out.println(response.statusCode());
            System.out.println(response.body());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

There can only be one concurrent scan per project.

Response

Here is a sample response after the scan is triggered and the build succeeds:

Copy icon Copy snippet

You can get the build details using the build details API once you receive the build number from the Visual scanner API response.

The API returns the following response if there is a failure:

Copy icon Copy snippet

Visual scanner API returns a success or failure response only after build finalization.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Download Copy