Help Center/ CodeArts Check/ API Reference/ APIs/ Code Metrics/ Obtaining Duplicate File Code
Updated on 2026-02-03 GMT+08:00

Obtaining Duplicate File Code

Function

This API is used to obtain the file code based on the file path, start and end lines, or duplicate block ID.

Calling Method

For details, see Calling APIs.

Authorization Information

Each account root user has all the permissions required to call all APIs, but IAM users must be assigned the following required identity policy-based permissions. For details about the required permissions, see Permissions Policies and Supported Actions.

Action

Access Level

Resource Type (*: required)

Condition Key

Alias

Dependencies

codeartscheck:task:getReport

Read

task *

-

-

-

-

codeartscheck:ProjectId

URI

POST /v1/measure/measure-duplication-info

Request Parameters

Table 1 Request header parameters

Parameter

Mandatory

Type

Description

X-Language

No

String

Definition:

Language of the response.

Constraints:

N/A

Value range:

  • zh-cn: Chinese.

  • en-us: English.

Default value:

zh-cn

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

taskId

Yes

String

Definition :

Task ID, returned by the API for creating a check task. Each code check task, branch task, or incremental task generated through an API has a unique ID. Obtain the ID by calling the API used to . id indicates the task ID.

Constraints:

N/A

Value range:

1 to 32 characters.

Default value:

N/A

jobId

No

String

Definition:

Execution ID, which is returned by the API of code check task execution. Each code check task has a unique execution ID. Leave this parameter blank for a version scan and pass a value for a quality gate scan. That is, the ID field in the response of API Querying Task Execution Record by Task ID.

Constraints:

N/A

Value range:

1 to 32 characters.

Default value:

N/A

filePath

Yes

String

Definition:

File path.

Constraints:

N/A

Range:

N/A

Default value:

N/A

blockId

No

String

Definition:

Duplicate code block ID.

Constraints:

Either startLine and endLine, or blockId is required.

Range:

N/A

Default value:

N/A

startLine

No

Integer

Definition:

Start line number.

Constraints:

Either startLine and endLine, or blockId is required.

Range:

N/A

Default value:

N/A

endLine

No

Integer

Definition:

End line number.

Constraints:

Either startLine and endLine, or blockId is required.

Range:

N/A

Default value:

N/A

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

status

String

Definition:

Response status.

Value range:

  • success: successful.

  • error: failed.

result

MeasureDuplicationInfo object

Definition:

Duplicate file code.

Table 4 MeasureDuplicationInfo

Parameter

Type

Description

codeHubFileUrl

String

Definition:

Suffix of the domain name for accessing the code repository of a file.

Value range:

N/A

rawLines

String

Definition:

Number of lines in the file.

Value range:

N/A

code

Array of CodeLine objects

Definition:

File code.

Table 5 CodeLine

Parameter

Type

Description

lineNumber

Integer

Definition:

Line No.

Value range:

N/A

lineContent

String

Definition:

Code.

Value range:

N/A

Status code: 400

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Definition:

Error code.

Value range:

N/A

error_msg

String

Definition:

Error message.

Value range:

N/A

Status code: 401

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Definition:

Error code.

Value range:

N/A

error_msg

String

Definition:

Error message.

Value range:

N/A

Example Requests

  • Query the code from line 1 to line 200 in the code/test.java file of the task whose ID is 897acf5exxx48a5013cd.

    POST https://{endpoint}/v1/measure/measure-duplication-info
    
    {
      "taskId" : "897acf5exxx48a5013cd",
      "filePath" : "code/test.java",
      "blockId" : "",
      "startLine" : 1,
      "endLine" : 200
    }
  • Query the code content of the duplicate block whose ID is 1 in the code/test.java file of the task whose ID is 897acf5exxx48a5013cd.

    POST https://{endpoint}/v1/measure/measure-duplication-info
    
    {
      "taskId" : "897acf5exxx48a5013cd",
      "filePath" : "code/test.java",
      "blockId" : "1"
    }

Example Responses

Status code: 200

Response body for obtaining the duplicate file code.

{
  "status" : "success",
  "error" : null,
  "result" : {
    "code" : [ {
      "lineNumber" : "18,",
      "lineContent" : "if ( typeof require !== \"undefined\" &&"
    }, {
      "lineNumber" : "19,",
      "lineContent" : "\ttypeof exports !== \"undefined\" &&"
    }, {
      "lineNumber" : "20,",
      "lineContent" : "\ttypeof module !== \"undefined\" ) {"
    }, {
      "lineNumber" : "21,",
      "lineContent" : "\t// Assume CommonJS"
    }, {
      "lineNumber" : "22,",
      "lineContent" : "\tGlobalize = require( \"globalize\" );"
    } ]
  }
}

Status code: 400

Bad Request

{
  "error_code" : "CC.xxxxxxxx.400",
  "error_msg" : "Verify request parameter failed. Check whether the request parameters are correct."
}

Status code: 401

Unauthorized

{
  "error_code" : "CC.00000003",
  "error_msg" : "Authentication information expired."
}

Status Codes

Status Code

Description

200

Response body for obtaining the duplicate file code.

400

Bad Request

401

Unauthorized

Error Codes

See Error Codes.