Calling data service APIs

Updated at:

You can use natural-language instructions to direct code agents, such as Qoder and CodeX, to call published and authorized APIs in the Dataphin data service using an application credential. This topic describes the feature, its prerequisites, and provides usage examples. An appendix lists the required input.

Overview

The data service API call capability lets you use natural-language instructions to call published and authorized APIs in the Dataphin data service to retrieve or write business data. Calls are initiated using a data service application's credential (AppKey and AppSecret). This capability supports three modes: A synchronous call returns results immediately, ideal for standard queries. An asynchronous call is for large datasets; it submits a task, polls for completion, and merges paginated results. A streaming call returns data in sequential chunks. All calls are directed to the data service gateway and can target either the development or production environment.

Use cases:

  • Call a published data service API to query business data.

  • Use an asynchronous call to retrieve complete results for large data queries.

  • Use a streaming call to get data in real-time chunks.

  • Perform data operations such as adding, updating, or deleting records through an API.

Note

Limitations: Before you make a call, the target API must be published to the corresponding environment, and the application must be authorized to access it. Calls must be authenticated using a data service application credential (AppKey and AppSecret), not an Alibaba Cloud account AccessKey. The call path and operation type (such as list query, single-item query, add, update, or delete) are determined by the operation type configured when the API was published. A specific success code in the response indicates a successful business operation. A successful HTTP status does not guarantee that the business operation succeeded; you must check the return code and the returned data to confirm the outcome.

Prerequisites

  • The target API is published to the environment you intend to call (development or production).

  • The data service application for the call is created and authorized to access the target API.

  • You have obtained the application's AppKey, AppSecret, and the data service gateway URL.

  • You know the target API's ID, operation type, and required business parameters.

Examples

Describe your needs to the agent in natural language. You can copy and use the following examples:

  • Use this application to call the customer list query API and return the first 10 records.

  • Call this API to query for a single customer record by ID.

  • The dataset is large, so use an asynchronous call for this list API and merge the results.

  • Call this API to add a new record.

Interaction steps:

  1. After you issue a command, the agent confirms the application credential, gateway URL, target API, and business parameters.

  2. If you only provide the application and API names, the agent typically looks up the necessary information, such as the credential, API ID, operation type, and authorized fields.

  3. The agent makes a synchronous, asynchronous, or streaming call. The credential information is not printed to the terminal or logs.

  4. After the call is complete, the agent formats and returns the business data, along with a confirmation of whether the call was successful.

Results

The operation returns the following results:

  • Response content: A synchronous call returns business data immediately. An asynchronous call returns the complete, merged results after pagination. A streaming call returns data in sequential chunks.

  • Completion status: A successful call is determined by the business success code in the response. For a list query, the results are in the list field. For a single-item query, the result is in the single-object field.

  • Review and validation: You can check the returned data to ensure it contains the expected business fields. If you receive an error, such as "unauthorized" or "path not bound to application," it usually means the application is not authorized or the operation type does not match. In such cases, you must grant the necessary permissions in the authorization step.

Note

A successful response indicates only that the request was processed. The data returned by the API and displayed in the Dataphin console is the final source of truth.

Appendix: Input

The following table lists the information required to call a data service API. The agent automatically identifies this information from your command and prompts you if anything is missing. You do not need to provide system-generated items.

Parameter

Required

Description

Example

Application AppKey

Yes

The AppKey for the data service application. It is obtained when you create the application and uniquely identifies it.

—

Application AppSecret

Yes

The AppSecret for the data service application, used to sign calls. This sensitive credential is not printed to the terminal or logs.

—

Gateway URL

Yes

The URL of the data service gateway. You can find this in the Network Configuration section of the Dataphin console.

—

API ID

Yes

The unique identifier for the target API. You can find this ID in the list of published APIs.

10083

Operation type

Yes

The operation type, determined when the API is published. Valid values are List Query, Single Query, Add, Update, and Delete.

LIST, GET

Publishing Environment

No

The environment where the API is published, such as production or development. Defaults to production.

RELEASE

Data Environment

No

The data environment to access, such as production or development. Defaults to production.

PROD

Business parameters

Conditionally Required

The request parameters defined by the API. You can only pass authorized fields.

—