UpdateFile - Update file content

Updated at:

Updates the content of a file in a code repository.

Applicable editions

Central edition and Central edition, Region edition

Endpoint and authorization information

  • Obtain an endpoint to replace the {domain} parameter in the request syntax.
  • Obtain a personal access token.
  • organizationId: Required only for the Central edition. In the Organization Management Console, go to the Basic Information page to obtain the organization ID.

Product

Resource

Required permission

Code Management

File

Read and write

Request syntax

Central edition

PUT https://{domain}/oapi/v1/codeup/organizations/{organizationId}/repositories/{repositoryId}/files/{rest:.*}

Region edition

PUT https://{domain}/oapi/v1/codeup/repositories/{repositoryId}/files/{rest:.*}

Request headers

Parameter

Type

Required

Description

Example

x-yunxiao-token

string

Yes

The personal access token.

pt-0fh3****0fbG_35af****0484

Request parameters

Parameter

Type

Location

Required

Description

Example

organizationId

string

path

  • Edition: Central edition

  • No: Region edition

The organization ID.

60d54f3daccf2bbd6659f3ad

repositoryId

string

path

Yes

The repository ID or the URL-encoded full path of the repository.

2813489 or 60de7a6852743a5162b5f957%2FDemoRepo

filePath

string

path

Yes

The file path. The path must be URL-encoded.

test.txt or src%2Fmain.java

-

object

body

No

branch

string

body

Yes

The branch name.

master

commitMessage

string

body

Yes

The commit message. It cannot be empty and must not exceed 102,400 characters.

update a file

content

string

body

Yes

The file content.

file content

encoding

string

body

No

The encoding format. Valid values are {text, base64}. The default value is text.

text

Request examples

Central edition

curl -X 'PUT' \
  'https://{domain}/oapi/v1/codeup/organizations/60d54f3daccf2bbd6659f3ad/repositories/{repository_id_or_encoded_path}/files/{rest:.*}' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484' \
  --data '
    {
        "branch": "master",
        "commitMessage": "update a file",
        "content": "file content",
        "encoding": "text"
    }'

Region edition

curl -X 'PUT' \
  'https://{domain}/oapi/v1/codeup/repositories/2813489or60de7a6852743a5162b5f957%2FDemoRepo/files/{rest:.*}' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484' \
  --data '
    {
        "branch": "master",
        "commitMessage": "update a file",
        "content": "file content",
        "encoding": "text"
    }'

Response parameters

Parameter

Type

Description

Example

-

object

branch

string

The branch name.

master

filePath

string

The file path.

src/test/main.java

Response example

{
    "branch": "master",
    "filePath": "src/test/main.java"
}

Error codes

For more information about API error codes, see the Error Code Center.