Updated on 2026-11-06 GMT+08:00

Using APIs to Connect to a Flink Endpoint and Submit Jobs

After creating a Flink endpoint on the AI DataLake console, you can submit Flink jobs to it and use its compute resources to process data. Currently, you can submit Flink SQL and Flink JAR jobs using APIs.

Prerequisites

  • You have obtained the workspace ID.

    Log in to the AI DataLake console and find the target workspace ID on the Workspace Management page.

  • You have obtained the Flink endpoint name (endpoint_name).

    Log in to the AI DataLake console, choose Engine Endpoints > Flink, and find the target Flink endpoint name.

  • You have created a job file based on the job type, uploaded the file to an OBS bucket, and recorded the OBS path.

Submitting a Flink SQL Job

Use a tool, such as Postman, to call the FlinkJob job creation API to create and start a Flink SQL job. The sample code is as follows:
POST /v2/workspaces/{workspace_id}/flink-jobs

{
  "name" : "test-flink-job",
  "description" : "Test the Flink SQL job.",
  "endpoint_name" : "Flink-endpoint-test",
  "job_agency" : "test-agencys",
  "execution_mode" : "STREAMING",
  "job_config" : {
    "type" : "FLINK_SQL_JOB",
    "sql_script_file" : "obs://bucket/path/to/script.sql",
    "dependency_jars" : [ "obs://bucket/path/to/dep1.jar" ]
  },
  "image_config": {
    "image_id": "dd877a59-5cbd-44c5-b8a7-dc464cca****",
    "image_version_id": "01ae8ee6-af8a-48a8-895b-8d4a70bf****"
  },
  "flink_config" : {
    "taskmanager.numberOfTaskSlots" : "1"
  },
  "autoscaling_policy" : {
    "enabled" : true,
    "vertex_max_parallelism" : 1000,
    "quota_cpu" : 4000,
    "quota_memory" : 8192,
    "custom_config" : {
      "job.autoscaler.target.utilization" : "0.6",
      "job.autoscaler.target.catch-up.duration" : "10 min"
    }
  },
  "resource_config" : {
    "parallelism" : 1,
    "jobmanager_resource_spec" : {
      "cpu" : 1000,
      "memory" : 4096
    },
    "taskmanager_resource_spec" : {
      "cpu" : 1000,
      "memory" : 4096
    }
  }
}
Table 1 Flink SQL job parameters

Parameter

Description

Example Value

workspace_id

The workspace ID.

Log in to the AI DataLake console and find the target workspace ID on the Workspace Management page.

980a81cf-8**1-4**6-b**9-c80******ed1

job_agency

The name of a user-defined agency, which authorizes the job to access OBS and other external resources.

test-agencys

endpoint_name

The endpoint name.

Log in to the AI DataLake console, choose Engine Endpoints > Flink, and find the target Flink endpoint name.

Flink-endpoint-test

type

The Flink job type.

FLINK_SQL_JOB

sql_script_file

The OBS path to the SQL script.

obs://bucket/path/to/script.sql

dependency_jars

A list of OBS paths to the JAR packages required by the SQL job.

obs://bucket/path/to/dep1.jar

image_id

The image ID. To obtain this value, call the API for Listing Custom Images.

dd877a59-5cbd-44c5-b8a7-dc464cca****

image_version_id

NOTE:

If the resource allocation mode of the endpoint is Hybrid or On-demand and an image snapshot is created for the selected image version, the snapshot is automatically associated when you select the image version. When the endpoint starts, the snapshot is automatically used to create image resources. No additional operation is required. For details about how to create an image snapshot, see Image Acceleration.

The image version. To view the image version, perform the following steps:

  1. On the AI DataLake console, choose Image Management in the left navigation pane.
  2. On the Built-in Images or Custom Images tab, click the image name.
  3. Verify the version of the built-in or custom image.
    • Check the built-in image version: Click the Versions tab, and view the image version in the Image Version column.
    • Check the custom image version: View the image version in the Image Version column.

      If no custom image is available, register one manually. For details, see Registering a Custom Image.

20e48735-f273-413c-a0f5-4cd4544f****

Submitting a Flink JAR Job

Use a tool, such as Postman, to call the FlinkJob job creation API to create and start a Flink JAR job. The sample code is as follows:
POST /v2/workspaces/{workspace_id}/flink-jobs

{
  "name" : "test-flink-jar-job",
  "description" : "Test the Flink JAR job.",
  "endpoint_name" : "Flink-endpoint-test",
  "job_agency" : "test-agencys",
  "execution_mode" : "STREAMING",
  "job_config" : {
    "type" : "FLINK_JAR_JOB",
    "main_jar" : "obs://bucket/path/jars/WindowJoin.jar",
    "main_class" : "org.apache.flink.streaming.examples.join.WindowJoin",
    "main_args" : [ "--input", "obs://bucket/input/", "--output", "obs://bucket/output/" ],
    "dependency_jars" : [ "obs://bucket/path/to/dep1.jar" ],
    "dependency_files" : [ "obs://bucket/path/to/config.csv" ]
  },
  "image_config": {
    "image_id": "dd877a59-5cbd-44c5-b8a7-dc464cca****",
    "image_version_id": "01ae8ee6-af8a-48a8-895b-8d4a70bf****"
  },
  "resource_config" : {
    "parallelism" : 1,
    "jobmanager_resource_spec" : {
      "cpu" : 1000,
      "memory" : 4096
    },
    "taskmanager_resource_spec" : {
      "cpu" : 1000,
      "memory" : 4096
    }
  }
}
Table 2 Flink JAR job parameters

Parameter

Description

Example Value

workspace_id

The workspace ID.

Log in to the AI DataLake console and find the target workspace ID on the Workspace Management page.

980a81cf-8**1-4**6-b**9-c80******ed1

job_agency

The name of a user-defined agency, which authorizes the job to access OBS and other external resources.

test-agencys

endpoint_name

The endpoint name.

Log in to the AI DataLake console, choose Engine Endpoints > Flink, and find the target Flink endpoint name.

Flink-endpoint-test

type

The Flink job type.

FLINK_JAR_JOB

main_jar

The OBS path of the JAR package containing the main class. This specifies the entry JAR package.

obs://bucket/path/jars/WindowJoin.jar

main_class

The fully qualified name of the JAR job entry class. This specifies the job entry class.

org.apache.flink.streaming.examples.join.WindowJoin

main_args

Entry class parameters for a JAR job.

"--input", "obs://bucket/input/", "--output", "obs://bucket/output/"

dependency_jars

A list of OBS paths to the JAR packages required by the JAR job.

obs://bucket/path/to/dep1.jar

dependency_files

The OBS path of the JAR job dependencies. This specifies the files required for job execution.

obs://bucket/path/to/config.csv

image_id

The image ID. To obtain this value, call the API for Listing Custom Images.

dd877a59-5cbd-44c5-b8a7-dc464cca****

image_version_id

NOTE:

If the resource allocation mode of the endpoint is Hybrid or On-demand and an image snapshot is created for the selected image version, the snapshot is automatically associated when you select the image version. When the endpoint starts, the snapshot is automatically used to create image resources. No additional operation is required. For details about how to create an image snapshot, see Image Acceleration.

The image version. To view the image version, perform the following steps:

  1. On the AI DataLake console, choose Asset Management > Images in the left navigation pane.
  2. On the Built-in Images or Custom Images tab, click the image name.
  3. Verify the version of the built-in or custom image.
    • Check the built-in image version: Click the Versions tab, and view the image version in the Image Version column.
    • Check the custom image version: View the image version in the Image Version column.

      If no custom image is available, register one manually. For details, see Registering a Custom Image.

20e48735-f273-413c-a0f5-4cd4544f****