The CustomApiResourceClient allows you to make HTTP requests to external APIs that you have configured as resources in Major.
Usage
import { myApiClient } from "./clients";
const result = await myApiClient.invoke("POST", "/v1/orders", "create-order", {
body: { type: "json", value: { productId: "p_123", quantity: 1 } },
headers: { "X-Custom-Auth": "secret" },
query: { currency: "USD" },
});
if (result.ok) {
console.log("Status:", result.result.status);
if (result.result.body.kind === "json") {
console.log("Response:", result.result.body.value);
}
}
The invoke method accepts the following arguments:
The HTTP method to use: "GET", "POST", "PUT", "PATCH", or "DELETE".
The URL path to append to the resource’s base URL.
A unique identifier for this operation.
Optional configuration object.
query
Record<string, string | string[]>
Query parameters to append to the URL.
Additional HTTP headers to send with the request.
The request body. Can be JSON, text, or bytes.
type
"json" | "text" | "bytes"
required
Required for json/text types.
Timeout in milliseconds (default: 30000).
Outputs
On success (ok: true), the result object contains:
Discriminator for the response type.
The HTTP status code returned by the API.
The response body.
kind
"json" | "text" | "bytes"
Present for json/text types.