Exclude Template Text
The Exclude Template feature allows you to refine the analysis of documents by excluding specific sections based on a predefined template. This is particularly useful for scenarios like checking student exams where the questions are the same for everyone, and you only want to scan the student’s answers.
This guide will walk you through the process of creating a template and then using it to exclude content from your scans.
How it Works
Section titled “How it Works”To better understand how template exclusion works, consider the following scenario where a teacher wants to scan student exams but exclude the questions.
| The Template | Student Submission | What Copyleaks Scans |
|---|---|---|
| (Indexed beforehand) | (The file you scan) | (The actual analysis) |
| Question 1: Explain the process of photosynthesis. | Question 1: Explain the process of photosynthesis. Answer: Photosynthesis is the process used by plants... | Question 1: Explain the process of photosynthesis. Answer: Photosynthesis is the process used by plants... |
By excluding the template text, the plagiarism scan focuses solely on the student’s original answer, preventing false positives from the question text itself.
Template Sourcing
Section titled “Template Sourcing”Templates for exclusion can be referenced in two ways:
- From a normal submitted scan: Reference any existing
scanIdfrom your submissions (saved short-term which is determined by theexpirationproperty). - From your Private Cloud Hub: Index the template document into your Private Cloud Hub (for recurring or long-term use).
This approach is widely used by many institutions to ensure that commonly repeated content, such as exam questions, rubrics, or boilerplate instructions, does not affect results.
🚀 Get Started
Section titled “🚀 Get Started”-
Before you begin
Section titled “Before you begin”Before you start, ensure you have the following:
- An active Copyleaks account. If you don’t have one, sign up for free.
- You can find your API key on the API Dashboard.
-
Installation
Section titled “Installation”Choose your preferred method for making API calls.
You can interact with the API using any standard HTTP client.
For a quicker setup, we provide a Postman collection. See our Postman guide for instructions.
Terminal window sudo apt-get install curlDownload it from curl.se
Terminal window brew install curlTerminal window pip install copyleaksTerminal window npm install plagiarism-checker -
To perform a scan, we first need to generate an access token. For that, we will use the login endpoint. The API key can be found on the Copyleaks API Dashboard.
Upon successful authentication, you will receive a token that must be attached to subsequent API calls via the Authorization: Bearer
<TOKEN>header. This token remains valid for 48 hours.POST https://id.copyleaks.com/v3/account/login/apiHeadersContent-Type: application/jsonBody{"key": "00000000-0000-0000-0000-000000000000"}Terminal window export COPYLEAKS_API_KEY="your-api-key-here"curl --request POST \--url https://id.copyleaks.com/v3/account/login/api \--header 'Accept: application/json' \--header 'Content-Type: application/json' \--data "{\"email\": \"${COPYLEAKS_EMAIL}\",\"key\": \"${COPYLEAKS_API_KEY}\"}"from copyleaks.copyleaks import CopyleaksAPI_KEY = "your-api-key-here"# Login to Copyleaksauth_token = Copyleaks.login(EMAIL_ADDRESS, API_KEY)print("Logged successfully!\nToken:", auth_token)const { Copyleaks } = require("plagiarism-checker");const API_KEY = "your-api-key-here";const copyleaks = new Copyleaks();// Login functionfunction loginToCopyleaks() {return copyleaks.loginAsync(EMAIL_ADDRESS, API_KEY).then((loginResult) => {console.log("Login successful!");console.log("Access Token:", loginResult.access_token);return loginResult;},(err) => {console.error('Login failed:', err);throw err;});}loginToCopyleaks();import com.copyleaks.sdk.api.Copyleaks;String API_KEY = "00000000-0000-0000-0000-000000000000";// Login to Copyleakstry {String authToken = Copyleaks.login(EMAIL_ADDRESS, API_KEY);System.out.println("Logged successfully!\nToken: " + authToken);} catch (CommandException e) {System.out.println("Failed to login: " + e.getMessage());System.exit(1);}Response
{"access_token": "<ACCESS_TOKEN>",".issued": "2025-07-31T10:19:40.0690015Z",".expires": "2025-08-02T10:19:40.0690016Z"} -
Create a Template (Index a Document)
Section titled “Create a Template (Index a Document)”First, you need to submit the document that contains the text you want to exclude (the template). You will “index” this document into a repository (either in your Private Cloud Hub or Shared Data Hub).
In this example, we will submit a file with the ID
my-template-indexto a repository namedmy_private_cloud_exam_template.PUT https://api.copyleaks.com/v3/scans/submit/file/my-template-indexContent-Type: application/jsonAuthorization: Bearer <YOUR_AUTH_TOKEN>{"base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu","filename": "exam_template.txt","properties": {"action": 2,"indexing": {"repositories": [{"id": "6e870e0bb2264","includeMySubmissions": true,"includeOthersSubmissions": true}],"copyleaksDb": false},"webhooks": {"status": "https://your-server.com/webhook/{STATUS}"}}}Terminal window curl -X PUT "https://api.copyleaks.com/v3/scans/submit/file/my-template-index" \-H "Authorization: Bearer <YOUR_AUTH_TOKEN>" \-H "Content-Type: application/json" \-d '{"base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu","filename": "exam_template.txt","properties": {"action": 2,"indexing": {"repositories": [{"id": "6e870e0bb2264","includeMySubmissions": true,"includeOthersSubmissions": true}],"copyleaksDb": false},"webhooks": {"status": "https://your-server.com/webhook/{STATUS}"},"sandbox": true}}'import requestsimport base64# Template contenttemplate_content = "This is the exam template text."base64_content = base64.b64encode(template_content.encode()).decode('utf-8')url = "https://api.copyleaks.com/v3/scans/submit/file/my-template-index"payload = {"base64": base64_content,"filename": "exam_template.txt","properties": {"action": 2,"indexing": {"repositories": [{"id": "6e870e0bb2264","includeMySubmissions": True,"includeOthersSubmissions": True}],"copyleaksDb": False},"webhooks": {"status": "https://your-server.com/webhook/{STATUS}"},"sandbox": True}}headers = {"Authorization": "Bearer <YOUR_AUTH_TOKEN>","Content-Type": "application/json"}response = requests.put(url, json=payload, headers=headers)print(response.json())const axios = require('axios');const url = 'https://api.copyleaks.com/v3/scans/submit/file/my-template-index';const headers = {'Authorization': 'Bearer <YOUR_AUTH_TOKEN>','Content-Type': 'application/json'};const data = {base64: "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",filename: "exam_template.txt",properties: {action: 2,indexing: {repositories: [{id: "6e870e0bb2264",includeMySubmissions: true,includeOthersSubmissions: true}],copyleaksDb: false},webhooks: {status: "https://your-server.com/webhook/{STATUS}"},sandbox: true}};axios.put(url, data, { headers }).then(response => console.log(response.data)).catch(error => console.error(error));import classes.Copyleaks;import models.submissions.CopyleaksFileSubmissionModel;import models.submissions.properties.*;import java.util.Base64;import java.nio.charset.StandardCharsets;String scanId = "my-template-index";String base64Content = Base64.getEncoder().encodeToString("This is the exam template text.".getBytes(StandardCharsets.UTF_8));// Create submission propertiesSubmissionProperties properties = new SubmissionProperties(new SubmissionWebhooks("https://your-server.com/webhook/{STATUS}"));properties.setSandbox(true);// Action 2 is 'Index Only'properties.setAction(SubmissionActions.IndexOnly);// Configure indexing to Private Cloud HubSubmissionIndexing indexing = new SubmissionIndexing();SubmissionRepo repo = new SubmissionRepo("6e870e0bb2264");repo.setIncludeMySubmissions(true);repo.setIncludeOthersSubmissions(true);indexing.setRepositories(new SubmissionRepo[]{repo});properties.setIndexing(indexing);// Create and submit the fileCopyleaksFileSubmissionModel submission = new CopyleaksFileSubmissionModel(base64Content, "exam_template.txt", properties);Copyleaks.submitFile(authToken, scanId, submission);System.out.println("Template indexed successfully."); -
Scan with Template Exclusion
Section titled “Scan with Template Exclusion”Now that you have a template indexed, you can submit a new document for scanning and tell Copyleaks to exclude the content of the template.
Use the
properties.exclude.documentTemplateIdsfield to specify the template ID.PUT https://api.copyleaks.com/v3/scans/submit/file/student-exam-submissionContent-Type: application/jsonAuthorization: Bearer <YOUR_AUTH_TOKEN>{"base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu","filename": "student_submission.txt","properties": {"action": 0,"webhooks": {"status": "https://your-server.com/webhook/{STATUS}"},"exclude": {"documentTemplateIds": ["my-template-index"]},"indexing": {"repositories": [{"id": "your-repo-id","includeMySubmissions": true,"includeOthersSubmissions": true}],"copyleaksDb": false},"aiGeneratedText": {"detect": true},"sandbox": true}}Terminal window curl -X PUT "https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission" \-H "Authorization: Bearer <YOUR_AUTH_TOKEN>" \-H "Content-Type: application/json" \-d '{"base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu","filename": "student_submission.txt","properties": {"action": 0,"webhooks": {"status": "https://your-server.com/webhook/{STATUS}"},"exclude": {"documentTemplateIds": ["my-template-index"]},"indexing": {"repositories": [{"id": "your-repo-id","includeMySubmissions": true,"includeOthersSubmissions": true}],"copyleaksDb": false},"aiGeneratedText": {"detect": true},"sandbox": true}}'import requestsimport base64# Student submission contentstudent_content = "This is the student's answer mixed with template text."base64_content = base64.b64encode(student_content.encode()).decode('utf-8')url = "https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission"payload = {"base64": base64_content,"filename": "student_submission.txt","properties": {"action": 0,"webhooks": {"status": "https://your-server.com/webhook/{STATUS}"},"exclude": {"documentTemplateIds": ["my-template-index"]},"indexing": {"repositories": [{"id": "your-repo-id","includeMySubmissions": True,"includeOthersSubmissions": True}],"copyleaksDb": False},"aiGeneratedText": {"detect": True},"sandbox": True}}headers = {"Authorization": "Bearer <YOUR_AUTH_TOKEN>","Content-Type": "application/json"}response = requests.put(url, json=payload, headers=headers)print(response.json())const axios = require('axios');const url = 'https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission';const headers = {'Authorization': 'Bearer <YOUR_AUTH_TOKEN>','Content-Type': 'application/json'};const data = {base64: "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",filename: "student_template.txt",properties: {action: 0,webhooks: {status: "https://your-server.com/webhook/{STATUS}"},exclude: {documentTemplateIds: ["my-template-index"]},indexing: {repositories: [{id: "your-repo-id",includeMySubmissions: true,includeOthersSubmissions: true}],copyleaksDb: false},aiGeneratedText: {detect: true},sandbox: true}};axios.put(url, data, { headers }).then(response => console.log(response.data)).catch(error => console.error(error));import classes.Copyleaks;import models.submissions.CopyleaksFileSubmissionModel;import models.submissions.properties.*;import java.util.Base64;import java.nio.charset.StandardCharsets;String scanId = "student-exam-submission";String base64Content = Base64.getEncoder().encodeToString("This is the student's answer mixed with template text.".getBytes(StandardCharsets.UTF_8));// Create submission propertiesSubmissionProperties properties = new SubmissionProperties(new SubmissionWebhooks("https://your-server.com/webhook/{STATUS}"));properties.setSandbox(true);// Set document templates to excludeSubmissionExclude exclude = new SubmissionExclude();exclude.setDocumentTemplateIds(new String[]{"my-template-index"});properties.setExclude(exclude);// Create and submit the fileCopyleaksFileSubmissionModel submission = new CopyleaksFileSubmissionModel(base64Content, "student_submission.txt", properties);Copyleaks.submitFile(authToken, scanId, submission);System.out.println("Scan submitted with template exclusion."); -
🎉 Congratulations!
Section titled “🎉 Congratulations!”You have just:
- ✅ Created a template document and indexed it
- ✅ Submitted a scan with template exclusion
- ✅ Excluded template text from your plagiarism analysis