API Reference Check Custom Code
Check Custom Code
Check one custom code file or page stylesheet against the rules a publish uses.
Session token
Checks the content of one file against the rules a publish uses for custom code from your docs, without saving anything. The web editor uses it for its live checks, so you get the same messages a publish would.
Note
Requires a session JWT and membership of the organization that owns {projectId} — any role. API keys are rejected with 401.
Path Parameters
NameDescription
projectIdThe project ID, a UUID.
Request Body
NameDescription
pathThe file's path from the docs folder, up to 500 characters.
_syntext/*.css, _syntext/*.js and _syntext/head.html are checked with their own rules; any other .css path is checked as a page stylesheet. Other paths return no errors.contentThe file's full text, up to 64 KB. A request body over that is refused with
413 payload_too_large; a file between the file limit and 64 KB gets the size message only.Response
NameDescription
data.errorsEvery rule the file breaks, in the words a publish uses — see What's refused. Empty when the file is fine. Limits across several files (all
_syntext/*.css together, the number of scripts) are checked at publish time.data.domainsFor a script or
head.html, the outside domains it loads from.Errors
| Status | Code | When |
|---|---|---|
| 400 | validation_error | path or content is missing or too long |
| 413 | payload_too_large | The request body is over 64 KB |
| 401 | unauthorized | No session token, an invalid or expired one, or an API key |
| 403 | forbidden | You're not a member of the project's organization |
| 404 | not_found | The project doesn't exist |
Was this page helpful? Yes No
Request
cURLJavaScriptPythonGoRubyPHPJavaC#cURL
curl -X POST https://api.syntext.dev/v1/projects/$PROJECT_ID/custom-scripts/check \
-H "Authorization: Bearer $SYNTEXT_JWT" \
-H "Content-Type: application/json" \
-d '{ "path": "_syntext/head.html", "content": "<base href=\"/\"><script defer src=\"https://plausible.io/js/script.js\"></script>" }'
// A browser has no environment variables: set these to your values.
const PROJECT_ID = '<PROJECT_ID>';
const SYNTEXT_JWT = '<SYNTEXT_JWT>';
const response = await fetch(`https://api.syntext.dev/v1/projects/${PROJECT_ID}/custom-scripts/check`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${SYNTEXT_JWT}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"path": "_syntext/head.html",
"content": "<base href=\"/\"><script defer src=\"https://plausible.io/js/script.js\"></script>"
}),
});
const data = await response.json();
console.log(response.status, data);
import os
import requests
url = f"https://api.syntext.dev/v1/projects/{os.environ['PROJECT_ID']}/custom-scripts/check"
headers = {
"Authorization": f"Bearer {os.environ['SYNTEXT_JWT']}",
}
payload = {
"path": "_syntext/head.html",
"content": "<base href=\"/\"><script defer src=\"https://plausible.io/js/script.js\"></script>",
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(response.json())
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)
func main() {
payload := []byte(`{
"path": "_syntext/head.html",
"content": "<base href=\"/\"><script defer src=\"https://plausible.io/js/script.js\"></script>"
}`)
req, err := http.NewRequest("POST", "https://api.syntext.dev/v1/projects/"+os.Getenv("PROJECT_ID")+"/custom-scripts/check", bytes.NewReader(payload))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("SYNTEXT_JWT"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(res.Status)
fmt.Println(string(body))
}
require "json"
require "net/http"
require "uri"
uri = URI("https://api.syntext.dev/v1/projects/#{ENV.fetch("PROJECT_ID")}/custom-scripts/check")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch("SYNTEXT_JWT")}"
request["Content-Type"] = "application/json"
request.body = JSON.generate({
"path" => "_syntext/head.html",
"content" => "<base href=\"/\"><script defer src=\"https://plausible.io/js/script.js\"></script>",
})
response = http.request(request)
puts response.code
puts response.body
<?php
$payload = [
'path' => '_syntext/head.html',
'content' => '<base href="/"><script defer src="https://plausible.io/js/script.js"></script>',
];
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.syntext.dev/v1/projects/' . getenv('PROJECT_ID') . '/custom-scripts/check',
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SYNTEXT_JWT'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException(curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
echo $status, PHP_EOL, $response, PHP_EOL;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"path": "_syntext/head.html",
"content": "<base href=\\"/\\"><script defer src=\\"https://plausible.io/js/script.js\\"></script>"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.syntext.dev/v1/projects/" + System.getenv("PROJECT_ID") + "/custom-scripts/check"))
.header("Authorization", "Bearer " + System.getenv("SYNTEXT_JWT"))
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
}
using System.Net.Http;
using System.Text;
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "https://api.syntext.dev/v1/projects/" + Environment.GetEnvironmentVariable("PROJECT_ID") + "/custom-scripts/check");
request.Headers.TryAddWithoutValidation("Authorization", "Bearer " + Environment.GetEnvironmentVariable("SYNTEXT_JWT"));
request.Content = new StringContent(
"""
{
"path": "_syntext/head.html",
"content": "<base href=\"/\"><script defer src=\"https://plausible.io/js/script.js\"></script>"
}
""",
Encoding.UTF8,
"application/json");
using var response = await client.SendAsync(request);
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(await response.Content.ReadAsStringAsync());
Responseapplication/json
200OK
{
"data": {
"errors": [
"<base> is not allowed (head.html may contain only <meta>, <link>, <script>, <noscript> and <style>)"
],
"domains": ["plausible.io"]
}
}