Invoking FunctionGraph Event Function using API Calls¶
This section demonstrates how to call a FunctionGraph implemented in Node.js using API calls and AK/SK-based authentication.
For details on AK/SK-based authentication, see
in Identity and Access Management (IAM) API reference.
Prerequisites¶
For details on prerequisites, see: Prerequisites
Using AK/SK authentication for API calls¶
Using AK/SK authentication the requests have to be signed with the AK/SK (or for temporal credentials with SecurityAccessKey/SecurityKey/SecurityToken).
For request signing the otc-api-sign-sdk-nodejs can be used.
The SDK provides a method to sign the request with AK/SK or SecurityAccessKey/SecurityKey/SecurityToken.
Additional to the environment variables mentioned in the prerequisites, you also need to set the following environment variables for AK/SK authentication :
OTC_SDK_AK (Access Key with permission to invoke FunctionGraph)
OTC_SDK_SK (Secret Key corresponding to the Access Key)
Synchronous invocation using AK/SK¶
Following sample code demonstrates how to invoke a FunctionGraph event function synchronously using API calls with AK/SK authentication.
See Executing a Function Synchronously in FunctionGraph API reference for more details about synchronous invocation.
const https = require("https");
const { Signer, HttpRequest } = require("otc-api-sign-sdk-nodejs");
const path = require("path");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
const projectId = process.env.OTC_SDK_PROJECT_ID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
const functionName = "nodejs-sample-invoke-function";
const functionVersion = "latest";
const functionApp = "default";
async function main() {
const functionURN = `urn:fss:${region}:${projectId}:function:${functionApp}:${functionName}:${functionVersion}`;
// Endpoint for synchronous invocation
const invokeURI = `${fgEndpoint}/v2/${projectId}/fgs/functions/${functionURN}/invocations`;
console.log("Invoke URI: ", invokeURI);
// X-Cff-Log-Type:
// "tail": 4KB logs will be returned
// "": no logs will be returned
const xCffLogType = "tail";
// X-CFF-Request-Version:
// "v0" response body in text format
// "v1" response body in json format
const xCffRequestVersion = "v1";
// set body according to your function input
const body = {
key: "Hello T-Cloud Public World - SYNC",
};
// set request method
const method = "POST";
// set headers
const headers = {
"Content-Type": "application/json;charset=utf8",
"Host": new URL(fgEndpoint).host,
"X-Cff-Log-Type": xCffLogType,
"X-CFF-Request-Version": xCffRequestVersion,
"X-Project-Id": projectId,
};
// create HttpRequest instance
const request = new HttpRequest(
method,
invokeURI,
headers,
JSON.stringify(body),
);
// create Signer instance and set AK/SK
const signer = new Signer();
signer.Key = ak;
signer.Secret = sk;
// sign the request
const signedRequest = signer.Sign(request);
// send the signed request
const req = https.request(signedRequest, function (res) {
res.setEncoding("utf8");
let data = "";
res.on("data", function (chunk) {
data += chunk.toString();
});
res.on("end", function () {
// output result
console.log("Result: ", JSON.parse(data).result);
// output logs
console.log("Log: ", JSON.parse(data).log);
});
});
req.on("error", function (e) {
console.error("Error: ", e);
});
req.write(JSON.stringify(body));
req.end();
}
main();
To execute the sample code, run the following command in the terminal
in folder samples-doc/invoke-fg:
node src/invokeSync_AKSK.js
# or use npm script:
npm run invokeSync_AKSK
const { Signer, HttpRequest } = require("otc-api-sign-sdk-nodejs");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
const projectId = process.env.OTC_SDK_PROJECT_ID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
const functionName = "nodejs-sample-invoke-function";
const functionVersion = "latest";
const functionApp = "default";
async function main() {
const functionURN = `urn:fss:${region}:${projectId}:function:${functionApp}:${functionName}:${functionVersion}`;
// Endpoint for synchronous invocation
const invokeURI = `${fgEndpoint}/v2/${projectId}/fgs/functions/${functionURN}/invocations`;
console.log("Invoke URI: ", invokeURI);
// X-Cff-Log-Type:
// "tail": 4KB logs will be returned
// "": no logs will be returned
const xCffLogType = "tail";
// X-CFF-Request-Version:
// "v0" response body in text format
// "v1" response body in json format
const xCffRequestVersion = "v1";
// set body according to your function input
const body = {
key: "Hello T-Cloud Public World - SYNC",
};
const bodyText = JSON.stringify(body);
// set request method
const method = "POST";
// set headers
const headers = {
"Content-Type": "application/json;charset=utf8",
"Host": new URL(fgEndpoint).host,
"X-Cff-Log-Type": xCffLogType,
"X-CFF-Request-Version": xCffRequestVersion,
"X-Project-Id": projectId,
};
// create HttpRequest instance
const request = new HttpRequest(method, invokeURI, headers, bodyText);
// create Signer instance and set AK/SK
const signer = new Signer();
signer.Key = ak;
signer.Secret = sk;
// sign the request
const signedRequest = signer.Sign(request);
// send signed request with Node.js fetch
try {
const response = await fetch(invokeURI, {
method: signedRequest.method,
headers: signedRequest.headers,
body: bodyText,
});
const data = await response.json();
if (!response.ok) {
console.error("Error: ", data);
return;
}
// output result
console.log("Result: ", data.result);
// output logs
console.log("Log: ", data.log);
} catch (error) {
console.error("Error: ", error);
}
}
main();
To execute the sample code, run the following command in the terminal
in folder samples-doc/invoke-fg:
node src/invokeSyncFetch_AKSK.js
# or use npm script:
npm run invokeSyncFetch_AKSK
In both cases, you should see an output similar to the following in the terminal:
Result: {"statusCode":200,"headers":{"Content-Type":"application/json"},"isBase64Encoded":false,"body":"{\"key\":\"Hello World\"}"}
Log: 2026-03-17T10:13:22Z Start invoke request '960d089c-c812-4fe7-9997-a72f773e4bcb', version: latest
2026-03-17T10:13:22Z 960d089c-c812-4fe7-9997-a72f773e4bcb INFO Function name: nodejs-sample-invoke-function
2026-03-17T10:13:22Z 960d089c-c812-4fe7-9997-a72f773e4bcb INFO Key value from event: Hello World
2026-03-17T10:13:22Z Finish invoke request '960d089c-c812-4fe7-9997-a72f773e4bcb', duration: 2.049ms, billing duration: 3ms, memory used: 36.535MB, billing memory: 128MB, cpu used: 0.300U, storage used: 0.039MB
Asynchronous invocation using AK/SK¶
Following sample code demonstrates how to invoke a FunctionGraph event function asynchronously using API calls with AK/SK authentication.
See Executing a Function Asynchronously in FunctionGraph API reference for more details about asynchronous invocation.
const https = require("https");
const { Signer, HttpRequest } = require("otc-api-sign-sdk-nodejs");
const path = require("path");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
const projectId = process.env.OTC_SDK_PROJECT_ID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
const functionName = "nodejs-sample-invoke-function";
const functionVersion = "latest";
const functionApp = "default";
async function main() {
const functionURN = `urn:fss:${region}:${projectId}:function:${functionApp}:${functionName}:${functionVersion}`;
// Endpoint for asynchronous invocation
const invokeURI = `${fgEndpoint}/v2/${projectId}/fgs/functions/${functionURN}/invocations-async`;
console.log("Invoke URI: ", invokeURI);
// set body according to your function input
const body = {
key: "Hello T-Cloud Public World - ASYNC ",
};
// set request method
const method = "POST";
// set headers
const headers = {
"Content-Type": "application/json;charset=utf8",
Host: new URL(fgEndpoint).host,
"X-Project-Id": projectId,
};
// create HttpRequest instance
const request = new HttpRequest(
method,
invokeURI,
headers,
JSON.stringify(body),
);
// create Signer instance and set AK/SK
const signer = new Signer();
signer.Key = ak;
signer.Secret = sk;
// sign the request
const signedRequest = signer.Sign(request);
// send the signed request
const req = https.request(signedRequest, function (res) {
res.setEncoding("utf8");
let data = "";
res.on("data", function (chunk) {
data += chunk.toString();
});
res.on("end", function () {
// output response
console.log("Response: ", data);
});
});
req.on("error", function (e) {
console.error("Error: ", e);
});
req.write(JSON.stringify(body));
req.end();
}
main();
To execute the sample code, run the following command in the terminal
in folder samples-doc/invoke-fg:
node src/invokeASync_AKSK.js
# or use npm script:
npm run invokeASync_AKSK
const { Signer, HttpRequest } = require("otc-api-sign-sdk-nodejs");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
const projectId = process.env.OTC_SDK_PROJECT_ID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
const functionName = "nodejs-sample-invoke-function";
const functionVersion = "latest";
const functionApp = "default";
async function main() {
const functionURN = `urn:fss:${region}:${projectId}:function:${functionApp}:${functionName}:${functionVersion}`;
// Endpoint for asynchronous invocation
const invokeURI = `${fgEndpoint}/v2/${projectId}/fgs/functions/${functionURN}/invocations-async`;
console.log("Invoke URI: ", invokeURI);
// set body according to your function input
const body = {
key: "Hello T-Cloud Public World - ASYNC ",
};
const bodyText = JSON.stringify(body);
// set request method
const method = "POST";
// set headers
const headers = {
"Content-Type": "application/json;charset=utf8",
Host: new URL(fgEndpoint).host,
"X-Project-Id": projectId,
};
// create HttpRequest instance
const request = new HttpRequest(method, invokeURI, headers, bodyText);
// create Signer instance and set AK/SK
const signer = new Signer();
signer.Key = ak;
signer.Secret = sk;
// sign the request
const signedRequest = signer.Sign(request);
// send signed request with Node.js fetch
try {
const response = await fetch(invokeURI, {
method: signedRequest.method,
headers: signedRequest.headers,
body: bodyText,
});
const data = await response.text();
if (!response.ok) {
console.error("Error: ", data);
return;
}
// output response
console.log("Response: ", data);
} catch (error) {
console.error("Error: ", error);
}
}
main();
To execute the sample code, run the following command in the terminal
in folder samples-doc/invoke-fg:
node src/invokeASyncFetch_AKSK.js
# or use npm script:
npm run invokeASyncFetch_AKSK
In both cases, you should see an output similar to the following in the terminal:
Response: {"request_id": "3d1a4f5a-b4e2-4429-80c8-3d82d2fe8791"}