Execute JavaScript
curl --request POST \
--url https://{deployment}/api/v1/javascript \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data @- <<EOF
{
"code": "const x = args[0] || 'world'; `hello ${x}`",
"args": [
"mmk"
],
"timeout": 5000
}
EOFimport requests
url = "https://{deployment}/api/v1/javascript"
payload = {
"code": "const x = args[0] || 'world'; `hello ${x}`",
"args": ["mmk"],
"timeout": 5000
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
code: 'const x = args[0] || \'world\'; `hello ${x}`',
args: ['mmk'],
timeout: 5000
})
};
fetch('https://{deployment}/api/v1/javascript', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{deployment}/api/v1/javascript",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => 'const x = args[0] || \'world\'; `hello ${x}`',
'args' => [
'mmk'
],
'timeout' => 5000
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{deployment}/api/v1/javascript"
payload := strings.NewReader("{\n \"code\": \"const x = args[0] || 'world'; `hello ${x}`\",\n \"args\": [\n \"mmk\"\n ],\n \"timeout\": 5000\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{deployment}/api/v1/javascript")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"const x = args[0] || 'world'; `hello ${x}`\",\n \"args\": [\n \"mmk\"\n ],\n \"timeout\": 5000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{deployment}/api/v1/javascript")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"const x = args[0] || 'world'; `hello ${x}`\",\n \"args\": [\n \"mmk\"\n ],\n \"timeout\": 5000\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"result": "hello mmk"
}
}{
"success": false,
"error": "<string>"
}{
"success": false,
"error": "<string>"
}JavaScript
Execute JavaScript
Runs JavaScript in a secure sandbox with a timeout. Requires a Basic license. Code is capped at 10 KB; timeout defaults to 5000 ms (max 10000 ms). Values in args are exposed to the script as the args array.
POST
/
javascript
Execute JavaScript
curl --request POST \
--url https://{deployment}/api/v1/javascript \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data @- <<EOF
{
"code": "const x = args[0] || 'world'; `hello ${x}`",
"args": [
"mmk"
],
"timeout": 5000
}
EOFimport requests
url = "https://{deployment}/api/v1/javascript"
payload = {
"code": "const x = args[0] || 'world'; `hello ${x}`",
"args": ["mmk"],
"timeout": 5000
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
code: 'const x = args[0] || \'world\'; `hello ${x}`',
args: ['mmk'],
timeout: 5000
})
};
fetch('https://{deployment}/api/v1/javascript', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{deployment}/api/v1/javascript",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => 'const x = args[0] || \'world\'; `hello ${x}`',
'args' => [
'mmk'
],
'timeout' => 5000
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{deployment}/api/v1/javascript"
payload := strings.NewReader("{\n \"code\": \"const x = args[0] || 'world'; `hello ${x}`\",\n \"args\": [\n \"mmk\"\n ],\n \"timeout\": 5000\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{deployment}/api/v1/javascript")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"const x = args[0] || 'world'; `hello ${x}`\",\n \"args\": [\n \"mmk\"\n ],\n \"timeout\": 5000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{deployment}/api/v1/javascript")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"const x = args[0] || 'world'; `hello ${x}`\",\n \"args\": [\n \"mmk\"\n ],\n \"timeout\": 5000\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"result": "hello mmk"
}
}{
"success": false,
"error": "<string>"
}{
"success": false,
"error": "<string>"
}Authorizations
Your deployment's API key (MMK_API_KEY). Routes that accept OAuth2 also allow Authorization: Bearer <token>.
Body
application/json
Was this page helpful?
⌘I

