Skip to content
HTTP & JSON httpStatus

$httpStatus[]

$httpStatus returns the status code of the response stored by the most recent HTTP request function, as a number text such as 200 or 404. It takes no argument.

Syntax

bdfd
$httpStatus[]

Behavior

  • An HTTP error status (4xx, 5xx) is returned like any other: the request functions do not raise an error for it, so test the code with $if to handle failures.
  • If no HTTP request has been made yet in the command, it raises the error A preceding HTTP request is required.
  • Each new request replaces the stored response.
  • A request that fails at the network level (connection refused, …) raises an error and does not produce a status.

Examples

Verify API Status Code

$httpGet[https://httpbin.org/status/200]
$title[HTTP Status Check]
$description[API endpoint returned HTTP status code: **$httpStatus** ✅]
$color[#57F287]

Handle a failure

$httpGet[https://api.example.com/items]
$if[$httpStatus==200]
  $sendMessage[OK: $httpResult]
$else
  $sendMessage[Request failed with status $httpStatus.]
$endif

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.