HTTP & JSON
httpAddHeader
$httpAddHeader[]
$httpAddHeader[name;value] stores a header that is sent with the next HTTP request only. Call it once per header before the request function. It returns an empty string.
Syntax
bdfd
$httpAddHeader[name;value]
Parameters
| Parameter | Description |
|---|---|
name |
Required. The header name; surrounding spaces are removed. An empty name raises HTTP header name cannot be empty. |
value |
Required (may be empty). The header value, used as written (spaces are kept). |
Behavior
- The pending headers are consumed by the next
$httpGet,$httpPost,$httpPut,$httpPatch,$httpDeleteor$httpHead: after that request they are cleared. A second request needs its own$httpAddHeadercalls. - The headers are cleared as soon as the request starts, including when the request then fails with an error.
- Calling it again with the same name (compared case-insensitively) replaces the previous value instead of adding a second header.
- The engine does not add a
Content-Typeof its own to JSON bodies: aPOSTwith a body and noContent-Typeheader is sent with the HTTP client’s default (text/plain; charset=utf-8in a local test), so setContent-Typewhen the API needsapplication/json.
Examples
Custom Headers for API Authentication
$httpAddHeader[Authorization;Bearer secret_api_token]
$httpAddHeader[Content-Type;application/json]
$httpGet[https://api.example.com/v1/profile]
$title[API Request with Custom Headers]
$description[Status: **$httpStatus**
Result: `$httpResult`]
$color[#00BCD4]
Try it
Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.