Skip to main content

HTTP

The HTTP service provides functionality for sending HTTP/HTTPS requests through the RPC methods HTTP.GET and HTTP.POST.

HTTP.GET#

This method allows fetching resources using HTTP/HTTPS GET requests.

Request#

Parameters:

  • url: string, url address of the request. Required
  • timeout: number, timeout in seconds. Optional
  • ssl_ca: string or null, type of the TCP socket. Optional
    • null or "" - default value, the built-in ca.pem TLS CA is used for HTTPS requests
    • "user_ca.pem" - the user-provided TLS CA is used for HTTPS requests, see Shelly.PutUserCA
    • * - disabled certificate validation
Make an HTTP GET request to a Shelly device with IP 10.33.53.21 to get its information.
http://10.33.53.21/rpc/HTTP.GET?url="http://10.33.53.21/rpc/Shelly.GetDeviceInfo"

Response#

Attributes in the result:

  • code: number, code of the HTTP response
  • message: string, message of the HTTP response
  • headers: object, list of HTTP headers sent by the server
  • body: string, HTTP response body, if Content-Type is text or application/json
  • or body_b64: base64 encoded HTTP response body, if body is binary data. Maximum accepted length is 16KB (16384 bytes)
{
"code": 200,
"message": "OK",
"headers": {
"Server": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Content-Length": "232",
"Connection": "close"
},
"body": "{\"id\":\"shellydev1-f008d1e2cb4c\", \"mac\":\"F008D1E2CB4C\", \"model\":\"SNSW-devX16EU\", \"gen\":2, \"fw_id\":\"20210908-124312/0.7.0-29-g0df1661-145-rpc-http-get-improvements-2\", \"ver\":\"0.7.0\", \"app\":\"Dev1\", \"auth_en\":false,\"auth_domain\":null}\r\n"
}

HTTP.POST#

This method allows posting data and receiving response using HTTP/HTTPS POST requests.

Request#

Parameters:

  • url: string, url address of the request. Required
  • body: string, the request body. Required
  • content_type: string, value of the Content-Type header sent with the request Optional, default is application/json
  • timeout: number, timeout in seconds. Optional
  • ssl_ca: string or null, type of the TCP socket. Optional
    • null or "" - default value, the built-in ca.pem TLS CA is used for HTTPS requests
    • "user_ca.pem" - the user-provided TLS CA is used for HTTPS requests, see Shelly.PutUserCA
    • * - disabled certificate validation
Make an HTTP POST request to a Shelly device with IP 10.33.53.21 to modify its configuration.
http://10.33.53.21/rpc/HTTP.POST?url=\"http://10.33.53.21/rpc/Sys.SetConfig\"&body=%7B%22config%22%3A%7B%22location%22%3A%7B%22tz%22%3A%22UTC%22%7D%7D%7D

Response#

Attributes in the result:

  • code: number, code of the HTTP response
  • message: string, message of the HTTP response
  • headers: object, list of HTTP headers sent by the server
  • body: string, HTTP response body, if Content-Type is text or application/json
  • or body_b64: base64 encoded HTTP response body, if body is binary data. Maximum accepted length is 16KB (16384 bytes)
{
"code": 200,
"message": "OK",
"headers": {
"Server": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}