Invoking FunctionGraph Event Function using API Calls

This section demonstrates how to call a FunctionGraph implemented in PHP 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-php 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.

<?php

require __DIR__ . '/../vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request as HttpRequest;
use OTC\Request as OTCRequest;
use OTC\Signer;

function main(): int
{
  $region = getenv('OTC_SDK_REGION') ?: 'eu-de';
  $projectId = getenv('OTC_SDK_PROJECTID');
  $ak = getenv('OTC_SDK_AK');
  $sk = getenv('OTC_SDK_SK');

  $missing = [];
  foreach ([
    'OTC_SDK_PROJECTID' => $projectId,
    'OTC_SDK_AK' => $ak,
    'OTC_SDK_SK' => $sk,
  ] as $name => $value) {
    if (empty($value)) {
      $missing[] = $name;
    }
  }

  if ($missing) {
    fwrite(STDERR, 'Missing required environment variables: ' . implode(', ', $missing) . PHP_EOL);
    return 1;
  }

  $fgEndpoint = "https://functiongraph.{$region}.otc.t-systems.com";
  $functionName = 'php-sample-invoke-function';
  $functionVersion = 'latest';
  $functionApp = 'default';

  $functionUrn = sprintf(
    'urn:fss:%s:%s:function:%s:%s:%s',
    $region,
    $projectId,
    $functionApp,
    $functionName,
    $functionVersion
  );

  $invokeUri = $fgEndpoint . '/v2/' . $projectId . '/fgs/functions/' . $functionUrn . '/invocations';
  echo "Invoke URI: {$invokeUri}" . PHP_EOL;

  $payload = json_encode([
    'key' => 'Hello T-Cloud Public World - SYNC',
  ], JSON_THROW_ON_ERROR);

  $headers = [
    'Content-Type' => 'application/json;charset=utf8',
    'Host' => "functiongraph.{$region}.otc.t-systems.com",
    'X-Cff-Log-Type' => 'tail',
    'X-CFF-Request-Version' => 'v1',
    'X-Project-Id' => $projectId,
  ];

  $request = new OTCRequest('POST', $invokeUri, $headers, $payload);

  $signer = new Signer();
  $signer->Key = $ak;
  $signer->Secret = $sk;
  $signer->Sign($request);

  $client = new Client([
    'verify' => false,
  ]);

  $signedHeaders = [];
  foreach ($signer->curlHeaders($request) as $headerValue) {
    [$headerName, $headerContent] = explode(':', $headerValue, 2);
    $signedHeaders[trim($headerName)] = trim($headerContent);
  }

  $httpRequest = new HttpRequest('POST', $invokeUri, $signedHeaders, $payload);

  try {
    $response = $client->send($httpRequest);
    $status = $response->getStatusCode();
    $responseBody = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR);

    echo 'Status: ' . $status . PHP_EOL;
    echo 'Result: ' . ($responseBody['result'] ?? '') . PHP_EOL;
    echo 'Log: ' . ($responseBody['log'] ?? '') . PHP_EOL;
    return 0;
  } catch (Throwable $exception) {
    fwrite(STDERR, 'Error: ' . $exception->getMessage() . PHP_EOL);
    return 1;
  }
}

exit(main());
{
  "name": "opentelekomcloud-community/invoke-fg-guzzle",
  "description": "Samples on how to invoke FunctionGraph functions using AK,SK and Guzzle",
  "license": "Apache-2.0",
  "type": "project",
  "require": {
    "opentelekomcloud-community/otc-api-sign-sdk-php": "1.0.2",
    "guzzlehttp/guzzle": "^7.0"
  }
}

To execute the sample code, run the following command in the terminal in folder samples-doc/invoke-fg/guzzle:

php src/invokeSync_AKSK.php

You should see an output similar to the following in the terminal:

Sample output of synchronous invocation using AK/SK
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: php-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.

<?php

require __DIR__ . '/../vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request as HttpRequest;
use OTC\Request as OTCRequest;
use OTC\Signer;

function main(): int
{
  $region = getenv('OTC_SDK_REGION') ?: 'eu-de';
  $projectId = getenv('OTC_SDK_PROJECTID');
  $ak = getenv('OTC_SDK_AK');
  $sk = getenv('OTC_SDK_SK');

  $missing = [];
  foreach ([
    'OTC_SDK_PROJECTID' => $projectId,
    'OTC_SDK_AK' => $ak,
    'OTC_SDK_SK' => $sk,
  ] as $name => $value) {
    if (empty($value)) {
      $missing[] = $name;
    }
  }

  if ($missing) {
    fwrite(STDERR, 'Missing required environment variables: ' . implode(', ', $missing) . PHP_EOL);
    return 1;
  }

  $fgEndpoint = "https://functiongraph.{$region}.otc.t-systems.com";
  $functionName = 'php-sample-invoke-function';
  $functionVersion = 'latest';
  $functionApp = 'default';

  $functionUrn = sprintf(
    'urn:fss:%s:%s:function:%s:%s:%s',
    $region,
    $projectId,
    $functionApp,
    $functionName,
    $functionVersion
  );

  $invokeUri = $fgEndpoint . '/v2/' . $projectId . '/fgs/functions/' . $functionUrn . '/invocations-async';
  echo "Invoke URI: {$invokeUri}" . PHP_EOL;

  $payload = json_encode([
    'key' => 'Hello T-Cloud Public World - ASYNC',
  ], JSON_THROW_ON_ERROR);

  $headers = [
    'Content-Type' => 'application/json;charset=utf8',
    'Host' => "functiongraph.{$region}.otc.t-systems.com",
    'X-Cff-Log-Type' => 'tail',
    'X-CFF-Request-Version' => 'v1',
    'X-Project-Id' => $projectId,
  ];

  $request = new OTCRequest('POST', $invokeUri, $headers, $payload);

  $signer = new Signer();
  $signer->Key = $ak;
  $signer->Secret = $sk;
  $signer->Sign($request);

  $client = new Client([
    'verify' => false,
  ]);

  $signedHeaders = [];
  foreach ($signer->curlHeaders($request) as $headerValue) {
    [$headerName, $headerContent] = explode(':', $headerValue, 2);
    $signedHeaders[trim($headerName)] = trim($headerContent);
  }

  $httpRequest = new HttpRequest('POST', $invokeUri, $signedHeaders, $payload);

  try {
    $response = $client->send($httpRequest);
    $status = $response->getStatusCode();
    $responseBody = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR);

    echo 'Status: ' . $status . PHP_EOL;
    echo 'Response Body: ' . json_encode($responseBody, JSON_THROW_ON_ERROR) . PHP_EOL;
    return 0;
  } catch (Throwable $exception) {
    fwrite(STDERR, 'Error: ' . $exception->getMessage() . PHP_EOL);
    return 1;
  }
}

exit(main());
{
  "name": "opentelekomcloud-community/invoke-fg-guzzle",
  "description": "Samples on how to invoke FunctionGraph functions using AK,SK and Guzzle",
  "license": "Apache-2.0",
  "type": "project",
  "require": {
    "opentelekomcloud-community/otc-api-sign-sdk-php": "1.0.2",
    "guzzlehttp/guzzle": "^7.0"
  }
}

To execute the sample code, run the following command in the terminal in folder samples-doc/invoke-fg/guzzle:

php src/invokeASync_AKSK.php

In both cases, you should see an output similar to the following in the terminal:

Sample output of asynchronous invocation using AK/SK
Response:  {"request_id": "3d1a4f5a-b4e2-4429-80c8-3d82d2fe8791"}