Request & Response
This is a configuration section of Custom MT. This section contains the core configuration for Machine Translation requests.
Variables
$ID$SOURCE_TEXTor$ORIGINAL_TEXT$TRANSLATED_TEXT$SOURCE_LANG$TARGET_LANG
Schema variables can be used in the configuration with the syntax $SCHEMA_NAME.
For example:
{
    "schema": [
        { "type": "string", "name": "api_key", "title": "API Key", "default": "", "required": true, "message": "Required an API Key" },
    ],
    "request": {
        "method": "http_post",
        "url": "http://127.0.01/?key=$API_KEY"
        "options": {
            "headers": {
              "Authorization": "Bearer $API_KEY",
              "Content-Type": "application/json"
            }
        }        
    }
}Parameters
method: string
string"web_scraping"
"http_get"
"http_post"
"web_llm"
initialUrl: string (optional)
string (optional)The initial URL to visit before making the actual request (for web scraping).
url: string
stringThe endpoint URL for the Machine Translation service.
encodeURI: boolean (optional)
boolean (optional)Escapes characters using UTF-8 code units, with each octet encoded in the format %XX, left-padded with 0 if necessary. Lone surrogates in UTF-16 do not encode any valid Unicode character.
Reference: encodeURI
encodeURIComponent: boolean (optional)
boolean (optional)Uses the same encoding algorithm as encodeURI.
Escapes all characters except: A–Z a–z 0–9 - _ . ! ~ * ' ( )
Reference: encodeURIComponent
encodeURIExtra: string (optional)
string (optional)Additional function to replace URI using a regular expression. For example: ["%2F", "g", "\\%2F"]
userAgent: string (optional)
string (optional)Custom User-Agent string for the HTTP request.
querySelector: string
stringReturns the first element within the HTML document that matches the specified selector or group of selectors. Reference: querySelector
querySelectorAll: string (optional)
string (optional)Returns a static NodeList representing a list of HTML elements that match the specified group of selectors. Reference: querySelectorAll
queryProperty: string
stringSpecifies which property to extract from the selected HTML element:
"value" - property of the HTMLDataElement [Reference]
"innerText" - property of the HTMLElement [Reference]
"textContent" - property of the Node [Reference]
"innerHTML" - property of the HTMLElement [Reference]
body: object
objectThe request body for POST requests. Can contain variables like $SOURCE_TEXT, $SOURCE_LANG, and $TARGET_LANG.
options: object (optional)
object (optional)Additional request options.
headers - Set custom request headers:
X-Custom-Header:
stringAuthorization:
stringContent-Type:
string
responseType: string
string"string" - set response type as string
"json" - set response type as json
responseQuery: string
stringParsing JSON Responses from HTTP Requests
JSON responses can be parsed using the responseQuery parameter.
The responseQuery parameter is only used for http_get and http_post methods when the response type is set to json.
To navigate through nested JSON objects, use dot notation (.) to separate field names. Array elements can be accessed using bracket notation with an index (e.g., [0]).
Example JSON Response:
{
  "text": "Hello 1",
  "words": [
    { "text": "Hello 2" },
    { "text": "Hello 3" }
  ]
  "lines": {
    "text": "Hello 4",
    "sub": {
      "text": "Hello 5"
    }        
  }
}text
Hello 1
words[0].text
Hello 2
lines.sub.text
Hello 5
Examples
1. Web Scraping Method

Required Parameters
method:
string("web_scraping")url:
stringquerySelector:
stringqueryProperty:
string
{
    "request": {
        "method": "web_scraping",
        "encodeURI": false,
        "encodeURIComponent": true, 
        "initialUrl": "https://localhost:8080",
        "url": "https://localhost:8080/?sl=$SOURCE_LANG&tl=$TARGET_LANG&text=$SOURCE_TEXT",    
        "querySelector": "span[lang=$TARGET_LANG]",
        "queryProperty": "innerText"
    }
}2. HTTP GET Method

Required Parameters
method:
string("http_get")url:
stringresponseType:
stringresponseQuery:
string
{
    "request": {
        "method": "http_get",
        "encodeURI": false,
        "encodeURIComponent": false, 
        "url": "https://localhost:8080/translate?sl=$SOURCE_LANG&tl=$TARGET_LANG&text=$SOURCE_TEXT",
        "options": {},
        "responseType": "json",
        "responseQuery": "translate.result"
    }
}3. HTTP POST Method

Required Parameters
method:
string("http_post")url:
stringbody:
objectoptions:
objectheaders:
objectX-Custom-Header: string
Authorization: string
Content-Type: string
responseType:
stringresponseQuery:
string
{
    "request": {
        "method": "http_post",
        "encodeURI": false,
        "encodeURIComponent": false, 
        "url": "https://localhost:8080/translate",
        "body": {
            "text": "$SOURCE_TEXT",
            "source_lang": "$SOURCE_LANG",
            "target_lang": "$TARGET_LANG"
        }
        "options": {
            "headers": {
                "Authorization": "Bearer $API_KEY",
                "Content-Type": "application/json"
            }
        },
        "responseType": "json",
        "responseQuery": "translate.result"
    }
}