CreateFile - Create a file

Updated at:

Creates a file in a code repository.

Applicable editions

Central edition, Region edition

Endpoint and authorization information

  • Obtain an endpoint. Replace {domain} in the API request syntax.
  • Obtain a personal access token.
  • Obtain the organizationId. Required only for the Central edition. You can go to the Basic Information page in the Organization Management console to obtain the organization ID.

Product

Resource

Required permission

Code Management

File

Read/Write

Request syntax

Central edition

POST https://{domain}/oapi/v1/codeup/organizations/{organizationId}/repositories/{repositoryId}/files

Region edition

POST https://{domain}/oapi/v1/codeup/repositories/{repositoryId}/files

Request header

Parameter

Type

Required

Description

Example

x-yunxiao-token

string

Yes

The personal access token.

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

Request parameters

Parameter

Type

Position

Required

Description

Example

organizationId

string

path

  • Yes, for the Central edition.

  • No, for the 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

-

object

body

No

branch

string

body

Yes

The branch name.

demo-branch

commitMessage

string

body

Yes

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

create a file with content

content

string

body

Yes

The file content.

file content

encoding

string

body

Yes

The encoding method. Valid values: `text` and `base64`. Default value: `text`.

text

filePath

string

body

Yes

The file path. Cannot be empty. Do not include special characters.

src/test/main.java

Request examples

Central edition

curl -X 'POST' \
  'https://{domain}/oapi/v1/codeup/organizations/60d54f3daccf2bbd6659f3ad/repositories/2813489 or 60de7a6852743a5162b5f957%2FDemoRepo/files' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484' \
  --data '
    {
        "branch": "demo-branch",
        "commitMessage": "create a file with content",
        "content": "file content",
        "encoding": "text",
        "filePath": "src/test/main.java"
    }'

Region edition

curl -X 'POST' \
  'https://{domain}/oapi/v1/codeup/repositories/2813489 or 60de7a6852743a5162b5f957%2FDemoRepo/files' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484' \
  --data '
    {
        "branch": "demo-branch",
        "commitMessage": "create a file with content",
        "content": "file content",
        "encoding": "text",
        "filePath": "src/test/main.java"
    }'

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 API error codes, see Error Code Center.