API Reference Move Custom Code Into Your Docs
Move Custom Code Into Your Docs
Move pasted CSS and snippets into _syntext/ files in your docs.
Session token
Moves the pasted code under Integrations › Custom code › Override (advanced) into the _syntext/ folder in your docs — the same as Move into your docs in the dashboard:
| Pasted code | Goes to |
|---|---|
| Custom CSS | _syntext/style.css |
Enabled head snippets that head.html allows | _syntext/head.html |
Enabled body snippets that are a plain inline <script> | _syntext/script.js |
Everything else — disabled snippets, and snippets that can't move as they are — stays pasted and is named in kept.
•
Written in Syntext — the files are created and the moved pasted code is cleared, in one step.
•
GitHub — a pull request is opened with the files. The pasted code is left as it is, so the site looks the same; remove it after you merge.
•
Published with
stx deploy — refused: Syntext doesn't store your files. Add the code to _syntext/ yourself and run stx deploy.Note
Requires a session JWT, and the admin or owner role in the organization that owns {projectId}. API keys are rejected with 401. No request body.
Path Parameters
NameDescription
projectIdThe project ID, a UUID.
Response
NameDescription
data.modehosted (files created in a project written in Syntext) or pull_request (GitHub).data.filesThe files written, such as
_syntext/style.css.data.clearedtrue when the moved pasted code was cleared (hosted); false on GitHub, where it stays until you remove it.data.keptThe pasted code that stayed where it is, by name.
data.switchesNeededThe switches that are still off and must be turned on for the moved code to apply:
css, head, scripts. Empty when they already are. Turn them on with Update Custom Code Switches.data.urlpull_request only: the pull request's address. data.number is its number.Errors
| Status | Code | When |
|---|---|---|
| 400 | nothing_to_move | There's no pasted code, or none of it can move as it is (details.kept names it) |
| 400 | unsupported_source | The project is published with stx deploy |
| 400 | invalid_custom_code | A file it would write breaks a rule. The message names the file and the first problem; details.errors lists them all |
| 401 | unauthorized | No session token, an invalid or expired one, or an API key |
| 403 | forbidden | You're not an admin or owner |
| 404 | not_found | The project doesn't exist |
| 409 | file_exists | A file it would write already exists in _syntext/. Rename or remove it first |
Was this page helpful? Yes No
Previous
Request
cURLJavaScriptPythonGoRubyPHPJavaC#cURL
curl -X POST https://api.syntext.dev/v1/projects/$PROJECT_ID/custom-scripts/move-to-docs \
-H "Authorization: Bearer $SYNTEXT_JWT"
// 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/move-to-docs`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${SYNTEXT_JWT}`,
},
});
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/move-to-docs"
headers = {
"Authorization": f"Bearer {os.environ['SYNTEXT_JWT']}",
}
response = requests.post(url, headers=headers)
print(response.status_code)
print(response.json())
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
req, err := http.NewRequest("POST", "https://api.syntext.dev/v1/projects/"+os.Getenv("PROJECT_ID")+"/custom-scripts/move-to-docs", nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("SYNTEXT_JWT"))
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 "net/http"
require "uri"
uri = URI("https://api.syntext.dev/v1/projects/#{ENV.fetch("PROJECT_ID")}/custom-scripts/move-to-docs")
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")}"
response = http.request(request)
puts response.code
puts response.body
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.syntext.dev/v1/projects/' . getenv('PROJECT_ID') . '/custom-scripts/move-to-docs',
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SYNTEXT_JWT'),
],
]);
$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 {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.syntext.dev/v1/projects/" + System.getenv("PROJECT_ID") + "/custom-scripts/move-to-docs"))
.header("Authorization", "Bearer " + System.getenv("SYNTEXT_JWT"))
.method("POST", HttpRequest.BodyPublishers.noBody())
.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/move-to-docs");
request.Headers.TryAddWithoutValidation("Authorization", "Bearer " + Environment.GetEnvironmentVariable("SYNTEXT_JWT"));
using var response = await client.SendAsync(request);
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(await response.Content.ReadAsStringAsync());
Responseapplication/json
200OK (GitHub
{
"data": {
"mode": "pull_request",
"url": "https://github.com/acme/docs/pull/57",
"number": 57,
"files": ["_syntext/style.css", "_syntext/head.html"],
"cleared": false,
"kept": ["Intercom"],
"switchesNeeded": ["head"]
}
}