Denizen Script Commands


Commands are always written with a '-' before them, and are the core component of any script, the primary way to cause things to happen.
Learn about how commands work in The Beginner's Guide.


Showing 1 out of 183 commands...
NameWebget
Syntaxwebget [<url>] (data:<data>) (method:<method>) (headers:<map>) (timeout:<duration>/{10s}) (savefile:<path>) (hide_failure)
Short DescriptionGets the contents of a web page or API response.
Full DescriptionConnects to a webpage or API and downloads its contents, to be used via the save argument and corresponding entry tags.

This should almost always be ~waited for. Refer to Language:~waitable.

Note that while this will replace URL spaces to %20, you are responsible for any other necessary URL encoding.
You may want to use the Tag:ElementTag.url_encode tag for this.

Optionally, use "data:<data>" to specify a set of data to send to the server (changes the default method from GET to POST).
A BinaryTag input will be used directly - any other input will be treated as a String and encoded as UTF-8.

Optionally, use "method:<method>" to specify the HTTP method to use in your request.
Can be: GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, PATCH.

Optionally, use "headers:" to specify a MapTag of headers.

Optionally, use "savefile:" to specify a path to save the retrieved file to.
This will remove the 'result' entry savedata.
Path is relative to server base directory.

Optionally, specify the "timeout:" to set how long the command should wait for a webpage to load before giving up. Defaults to 10 seconds.

Optionally, specify 'hide_failure' to indicate that connection errors are acceptable and shouldn't display in logs.

This command accepts secret inputs via ObjectType:SecretTag as the URL or as the value of any header.
Note that you cannot mix secret with non-secret - meaning, "webget <secret[my_secret]>" and "webget https://example.com" are both valid, but "webget https://example.com/<secret[my_secret]>" is not.
Similarly, for headers, each individual header value can either be a secret or not a secret.
Related Tags<entry[saveName].failed> returns whether the webget failed. A failure occurs when the status is not 2XX/3XX or webget failed to connect.
<entry[saveName].result> returns the text of the result of the webget. This is null only if webget failed to connect to the url.
<entry[saveName].result_binary> returns the raw binary data of the result of the webget. This is null only if webget failed to connect to the url.
<entry[saveName].result_headers> returns a MapTag of the headers returned from the webserver. Every value in the result is a list.
<entry[saveName].status> returns the HTTP status code of the webget. This is null only if webget failed to connect to the url.
<entry[saveName].time_ran> returns a DurationTag indicating how long the web connection processing took.
<ElementTag.url_encode> Encodes the element using URL encoding.
Usage Example
#Use to download the google home page.
- ~webget https://google.com save:google
- narrate <entry[google].result>
Usage Example
#Use to save a webpage to your server's base directory
- ~webget https://google.com savefile:google.html
Usage Example
#Use to post data to a server.
- ~webget https://api.mojang.com/orders/statistics 'data:{"metricKeys":["item_sold_minecraft"]}' headers:<map.with[Content-Type].as[application/json]> save:request
- narrate <entry[request].result>
Usage Example
#Use to retrieve and load an API response into yaml.
- ~webget https://api.mojang.com/users/profiles/minecraft/<player.name> save:request
- yaml loadtext:<entry[request].result> id:player_data
Synonyms (Search Aid)wget
Groupcore
Sourcehttps://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/scripts/commands/core/WebGetCommand.java#L39