PowerKeys Scripting API
    Preparing search index...

    Interface HTTPAPI

    interface HTTPAPI {
        SendRequest(
            url: string,
            method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH",
            body?: HttpRequestBody,
        ): Promise<HttpResponse>;
    }
    Index
    • Sends an HTTP request and resolves with the response.

      When a non-null body is provided, the Content-Type header is automatically set to application/json. Strings are sent verbatim; other accepted values are serialized as compact JSON text.

      Parameters

      • url: string

        The full URL to send the request to.

      • Optionalmethod: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"

        HTTP method. Defaults to GET.

      • Optionalbody: HttpRequestBody

        Optional JSON-serializable body. Omit or pass null for no body. Strings are sent verbatim; other values are JSON-serialized.

      Returns Promise<HttpResponse>

      A promise for an HttpResponse with the status code and response body.

      Network-level failures (timeout, DNS error, connection refusal, or response-body read failure) reject the Promise and should be handled with try/catch. HTTP 4xx/5xx responses resolve normally with their real status code. Request timeout is 30 s; connection timeout is 10 s. Method matching is case-insensitive at runtime; the uppercase spellings in the type are canonical.

      // GET request
      try {
      const res = await HTTP.SendRequest("https://api.example.com/data", "GET");
      if (res.statusCode === 200) {
      const data = JSON.parse(res.body);
      Console.Log(data.value);
      }
      } catch (error) {
      Console.Error("Network error: " + error);
      }

      // POST with JSON body
      const post = await HTTP.SendRequest(
      "https://api.example.com/items",
      "POST",
      { name: "test" }
      );

      network