External Services
External service calls let code read small HTTP responses, check Minecraft server status, or send Discord webhooks. Keep these calls lightweight. Network calls can fail, and both engines limit requests to protect code execution.
HTTP JSON
Use this when an API returns JSON and code needs fields from the response.
- Engine v2
- Engine v1
Fetches JSON from a URL through the v2 runtime HTTP helper.
const data = http.getJson("https://httpbin.org/json");
async.messages.send(data.slideshow.title);
API reference
http.getJson
http.getJson(url)
Input
urlstringAbsolute URL to request.
Output
anyParsed JSON response body.
Example output
{
"status": "online",
"viewers": 42
}
{{$response := http.GetJson "https://swapi.dev/api/people/1"}}
Name: {{$response.name}}
HTTP JSON with Headers
Use headers when the external API requires tokens or accepts custom content negotiation.
- Engine v2
- Engine v1
Runs an HTTP request synchronously and returns a small Fetch-like response object.
const response = fetchSync("https://httpbin.org/json", {
headers: { Accept: "application/json" },
});
const data = response.json();
async.messages.send(data.slideshow.title);
API reference
fetchSync
fetchSync(url, options?)
Input
urlstringAbsolute URL to request.
optionsoptionalobjectRequest options.
methodoptionalstringHTTP method. Defaults to GET.
headersoptionalobjectHeader names mapped to header values.
bodyoptionalstringobjectarraynumberbooleannullRequest body. Objects and arrays are sent as JSON.
Output
objectFetch-like response.
statusnumberHTTP status code.
okbooleanTrue for successful 2xx responses.
headersobjectResponse headers.
textfunctionReturns the response body as text.
jsonfunctionParses and returns the response body as JSON.
Example output
{
"status": 200,
"ok": true,
"headers": {
"content-type": "application/json"
}
}
Runs an HTTP request and returns a Fetch-like response object.
API reference
fetch
fetch(url, options?)
Input
urlstringAbsolute URL to request.
optionsoptionalobjectRequest options.
methodoptionalstringHTTP method. Defaults to GET.
headersoptionalobjectHeader names mapped to header values.
bodyoptionalstringobjectarraynumberbooleannullRequest body. Objects and arrays are sent as JSON.
Output
objectFetch-like response.
statusnumberHTTP status code.
okbooleanTrue for successful 2xx responses.
headersobjectResponse headers.
textfunctionReturns the response body as text.
jsonfunctionParses and returns the response body as JSON.
Example output
{
"status": 200,
"ok": true,
"headers": {
"content-type": "application/json"
}
}
{{$response := http.GetJsonWithHeaders "https://example.com" (dict "Authorization" "mySuperSecretToken")}}
Name: {{$response.name}}
HTTP Text
Use this when an endpoint returns plain text.
- Engine v2
- Engine v1
Fetches text from a URL through the v2 runtime HTTP helper.
const status = http.getText("https://example.com/status.txt");
async.messages.send(`Status: ${status}`);
API reference
http.getText
http.getText(url)
Input
urlstringAbsolute URL to request.
Output
stringResponse body text.
{{http.GetText "https://example.com/status.txt"}}
HTTP Text with Headers
- Engine v2
- Engine v1
Runs an HTTP request synchronously and returns a small Fetch-like response object.
const response = fetchSync("https://example.com/status", {
headers: { Authorization: "Bearer token" },
});
async.messages.send(response.text());
API reference
fetchSync
fetchSync(url, options?)
Input
urlstringAbsolute URL to request.
optionsoptionalobjectRequest options.
methodoptionalstringHTTP method. Defaults to GET.
headersoptionalobjectHeader names mapped to header values.
bodyoptionalstringobjectarraynumberbooleannullRequest body. Objects and arrays are sent as JSON.
Output
objectFetch-like response.
statusnumberHTTP status code.
okbooleanTrue for successful 2xx responses.
headersobjectResponse headers.
textfunctionReturns the response body as text.
jsonfunctionParses and returns the response body as JSON.
Example output
{
"status": 200,
"ok": true,
"headers": {
"content-type": "application/json"
}
}
{{http.GetTextWithHeaders "https://example.com/status" (dict "Authorization" "mySuperSecretToken")}}
HTTP POST JSON
- Engine v2
- Engine v1
Sends JSON to a URL through the v2 runtime HTTP helper.
const result = http.postJson("https://example.com/api", {
username: sender.username,
});
async.messages.send(result.ok ? "Sent." : "Failed.");
API reference
http.postJson
http.postJson(url, body)
Input
urlstringAbsolute URL to request.
bodyobjectarraystringnumberbooleannullJSON-serializable request body.
Output
anyParsed JSON response body when the response is JSON.
Example output
{
"ok": true,
"id": "evt_123"
}
POST JSON is not exposed in the v1 template HTTP API.
Fetch API
Engine v2 also exposes fetchSync(url, options) and fetch(url, options).
- Engine v2
- Engine v1
Runs an HTTP request synchronously and returns a small Fetch-like response object.
const response = fetchSync("https://example.com/data.json");
if (response.ok) {
async.messages.send(response.json().name);
} else {
async.messages.send(`Request failed with ${response.status}`);
}
API reference
fetchSync
fetchSync(url, options?)
Input
urlstringAbsolute URL to request.
optionsoptionalobjectRequest options.
methodoptionalstringHTTP method. Defaults to GET.
headersoptionalobjectHeader names mapped to header values.
bodyoptionalstringobjectarraynumberbooleannullRequest body. Objects and arrays are sent as JSON.
Output
objectFetch-like response.
statusnumberHTTP status code.
okbooleanTrue for successful 2xx responses.
headersobjectResponse headers.
textfunctionReturns the response body as text.
jsonfunctionParses and returns the response body as JSON.
Example output
{
"status": 200,
"ok": true,
"headers": {
"content-type": "application/json"
}
}
Use http.GetJson, http.GetText, http.GetJsonWithHeaders, or http.GetTextWithHeaders instead.
Minecraft Status
Use this to read a Minecraft server status response.
- Engine v2
- Engine v1
Returns the current player count for a Minecraft server.
API reference
minecraft.players
minecraft.players(host)
Input
hoststringMinecraft server host.
Output
numberCurrent player count.
const players = minecraft.players("mc.example.com");
async.messages.send(`Players: ${players}`);
For the full status object:
Returns the Minecraft server status from mcapi.us, including online state and player counts.
API reference
minecraft.status
minecraft.status(host)
Input
hoststringMinecraft server host.
Output
objectMinecraft server status response.
onlinebooleanWhether the server is online.
playersobjectPlayer count information.
nownumberCurrent player count.
maxnumberMaximum player count reported by the server.
const status = minecraft.status("mc.example.com");
async.messages.send(`Online: ${status.online}
Players: ${status.players.now}`);
There are currently {{minecraft.Players "hypixel.net"}} players on Hypixel.net!
Discord Webhooks
Use Discord webhooks when code should send a message to a Discord channel.
- Engine v2
- Engine v1
Sends a message to a Discord webhook.
API reference
discord.send
discord.send(webhookUrl, payload)
Input
webhookUrlstringDiscord webhook URL.
payloadobjectDiscord webhook payload, for example {content: "..."}.
Output
booleanTrue when the webhook send completed.
discord.send("https://discord.com/api/webhooks/xx/xx", {
content: `${sender.username} triggered a command.`,
});
async.messages.send("Discord webhook sent.");
In v1, define a template block containing the Discord JSON payload, then pass that block name to discord.SendMessage.
{{discord.SendMessage "https://discord.com/api/webhooks/xx/xx" "discord"}}
{{define "discord"}}
{"content": "{{sender}} triggered a command."}
{{end}}
Advanced Script:
const json = {
content: "Hello from JavaScript!",
};
Discord.sendMessage("https://discord.com/api/webhooks/xx/xx", json);
Custom Events
Custom events notify overlay widgets and are documented with the other overlay helpers. See Overlay Effects.
Async external-service wrappers
Async wrapper for http.getJson(url).
API reference
async.http.getJson
async.http.getJson(url)
Input
urlstringAbsolute URL to request.
Output
anyParsed JSON response body.
Example output
{
"status": "online",
"viewers": 42
}
Async wrapper for http.getText(url).
API reference
async.http.getText
async.http.getText(url)
Input
urlstringAbsolute URL to request.
Output
stringResponse body text.
Async wrapper for http.postJson(url, body).
API reference
async.http.postJson
async.http.postJson(url, body)
Input
urlstringAbsolute URL to request.
bodyobjectarraystringnumberbooleannullJSON-serializable request body.
Output
anyParsed JSON response body when the response is JSON.
Example output
{
"ok": true,
"id": "evt_123"
}
Async wrapper for discord.send(webhookUrl, payload).
API reference
async.discord.send
async.discord.send(webhookUrl, payload)
Input
webhookUrlstringDiscord webhook URL.
payloadobjectDiscord webhook payload, for example {content: "..."}.
Output
booleanTrue when the webhook send completed.
Async wrapper for minecraft.players(host).
API reference
async.minecraft.players
async.minecraft.players(host)
Input
hoststringMinecraft server host.
Output
numberCurrent player count.
Async wrapper for minecraft.status(host).
API reference
async.minecraft.status
async.minecraft.status(host)
Input
hoststringMinecraft server host.
Output
objectMinecraft server status response.
onlinebooleanWhether the server is online.
playersobjectPlayer count information.
nownumberCurrent player count.
maxnumberMaximum player count reported by the server.
Limits and Safety
v1 HTTP template calls are limited to 3 requests per render and response bodies are limited. v1 Minecraft status calls are limited to 3 unique servers per render. v1 Discord webhook sends are limited to 3 messages per render.
v2 HTTP, fetchSync, and remote-import network requests are limited to 3 requests per render. Discord sends are limited to 3 sends per render. Minecraft status calls are limited to 3 requests per render. All external network actions together are limited to 6 per render.
v2 blocks local, numeric-IP, Kick, and other unsafe request targets for HTTP calls. Discord sends are restricted to https://discord.com URLs. Each outbound HTTP call has a 5 second request timeout and a 256 KB response body limit, and the whole render still runs inside the normal v2 execution timeout and memory limits.