Skip to main content

APIs

APIs provide a flexible way to invoke the V2 version APIs Connector. For creating V2 version APIs, see the documentation.

Note

The v3 version uses the open capabilities of the HTTP API when calling general APIs.


APIs Usage Reference

interface apis {
[apisLabel: string]: {
[
method: "request" | "post" | "get" | "head" | "patch" | "delete" | "put"
]: (
callApiOptions: ICallApiOptions,
opts?: IRequestOptions
) => Promise<ResponseObject["data"]>;
};
}

APIs module supports the following HTTP methods:

MethodDescriptionExample
getGET requestapis["apisLabel"].get(callApiOptions)
postPOST requestapis["apisLabel"].post(callApiOptions)
putPUT requestapis["apisLabel"].put(callApiOptions)
deleteDELETE requestapis["apisLabel"].delete(callApiOptions)
headHEAD requestapis["apisLabel"].head(callApiOptions)
patchPATCH requestapis["apisLabel"].patch(callApiOptions)
requestCustom method requestapis["apisLabel"].request(callApiOptions)
Tip

apisLabel is the APIs identifier, generated when creating the V2 version APIs Connector, and can be found in the connector's basic information.

参数

callApiOptions
ICallApiOptions
opts
IRequestOptions

Request object parameters, generally not required to be passed, include url, method, headers, and body. They serve as supplementary options for customization needs and will override parameters of the same name in callApiOptions.

返回

res
ResponseObject['data']

data content returned by the HTTP interface

示例

// Call the methodLabel method of the API connector named "apisLabel" using a POST call
async function getUserProfile(userId: string) {
try {
const result = await apis["apisLabel"].post({
path: "methodLabel",
body: { userId },
});
console.log("Call successful:", result);
return result;
} catch (error) {
console.error("Call failed:", error);
throw error;
}
}

// Call the methodLabel method of the API connector named "apisLabel" using a GET call
async function getProductList(category: string) {
try {
const result = await apis["apisLabel"].get({
path: "methodLabel",
body: { category },
});
return result;
} catch (error) {
console.error("Call failed:", error);
throw error;
}
}