Skip to content

Update a file

PUT /api/v5/repos/{owner}/{repo}/contents/{path}

This endpoint updates the content of a file at the specified path in the specified repository. The request must provide the base64-encoded new file content, the Blob SHA of the original file, and a commit message. You can specify the target branch and the commit author. On success, it returns the commit record and the updated file content.

Access token support

  • AtomGit user access tokens (AtomGit user access tokens)

Anonymous access

This endpoint does not allow anonymous access.

Request parameters

Parameter Location Type Required Description
owner path string Yes Namespace address the repository belongs to (organization or personal path)
repo path string Yes Repository path (path)
path path string Yes File path
access_token query string Yes User authorization code

Request Body:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "content": {
      "description": "File content; must be base64-encoded",
      "type": "string"
    },
    "sha": {
      "description": "Blob SHA of the file",
      "type": "string"
    },
    "branch": {
      "description": "Branch name. Defaults to the repository's default branch",
      "type": "string"
    },
    "message": {
      "description": "Commit information",
      "type": "string"
    },
    "author": {
      "description": "Commit author information",
      "type": "object",
      "properties": {
        "name": {
          "description": "Author name; defaults to the current user's name",
          "type": "string"
        },
        "email": {
          "description": "Author email; defaults to the current user's email",
          "type": "string"
        }
      }
    }
  },
  "required": ["content", "sha", "message"]
}

Response parameters

Field Type Always returned Nullable Description
commit object Yes No Commit information
content object Yes No Updated file content information

commit object

Field Type Always returned Nullable Description
commit.sha string Yes No Commit SHA
commit.author object Yes No Commit author
commit.committer object Yes No Committer
commit.message string Yes No Commit information
commit.tree string Yes No SHA of the file tree for the commit
commit.parents string[] Yes No List of parent commit SHAs

commit.author object

Field Type Always returned Nullable Description
commit.author.name string Yes No Author name
commit.author.email string Yes No Author email
commit.author.date string Yes No Author commit time

commit.committer object

Field Type Always returned Nullable Description
commit.committer.name string Yes No Committer name
commit.committer.email string Yes No Committer email
commit.committer.date string Yes No Commit time

content object

Field Type Always returned Nullable Description
content.name string Yes No File name
content.path string Yes No File path
content.size integer Yes No File size
content.sha string Yes No File content SHA
content.type string Yes No File type

Error responses

A success response alone is not enough: callers need to know what failures look like in order to write error handling.

400 Invalid parameters

{
  "error": "invalid_request",
  "message": "The message parameter cannot be empty"
}

401 Unauthenticated

{
  "error": "unauthorized",
  "message": "Missing or invalid access token"
}

Note: The error response field names are subject to the actual backend response.

HTTP response status codes

Status code Description
200 Success (OK)
400 Invalid parameters
401 Authentication required (Requires authentication)
403 Forbidden
404 Resource not found (Not found)

Request example

Parameter notes

The example is consistent with the rest of this document; you can copy it as-is and the call will succeed:

  • Replace <owner> with the namespace address the repository belongs to (organization or personal path);
  • Replace <repo> with the repository path (path);
  • Replace <path> with the file path;
  • Replace <token> with your AtomGit user access token;
  • Replace <file_sha> with the Blob SHA of the file;
  • Replace <branch> with the branch name (optional; defaults to the repository's default branch).

cURL

curl -X PUT 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/contents/<path>?access_token=<token>' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "content": "SGVsbG8gV29ybGQK",
    "sha": "<file_sha>",
    "branch": "<branch>",
    "message": "update file"
  }'

JavaScript

// Native fetch (Node.js 18+ / browser)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/contents/<path>?access_token=<token>", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
  },
  body: JSON.stringify({
    content: "SGVsbG8gV29ybGQK",
    sha: "<file_sha>",
    branch: "<branch>",
    message: "update file",
  }),
});

if (!response.ok) {
  throw new Error(`Request failed: ${response.status}`);
}

const data = await response.json();
console.log(data);

Python

import requests

resp = requests.put(
    "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/contents/<path>",
    params={"access_token": "<token>"},
    json={
        "content": "SGVsbG8gV29ybGQK",
        "sha": "<file_sha>",
        "branch": "<branch>",
        "message": "update file",
    },
    headers={"Accept": "application/json"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

Response example

Status code: 200

{
  "commit": {
    "sha": "0f9a4c7b2e6d4f8a1b3c5d7e9f0a2b4c6d8e0f1a",
    "author": {
      "name": "octocat",
      "email": "octocat@atomgit.com",
      "date": "2026-10-12T13:33:48+08:00"
    },
    "committer": {
      "name": "octocat",
      "email": "octocat@atomgit.com",
      "date": "2026-10-12T13:33:48+08:00"
    },
    "message": "update file",
    "tree": "2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a",
    "parents": ["5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b"]
  },
  "content": {
    "name": "Note.md",
    "path": "Note.md",
    "size": 1024,
    "sha": "6dcd4ce23d88e2ee9568ba546c007c63d9131c1b",
    "type": "file"
  }
}

Error codes

Error code Description
401 Unauthenticated or invalid credentials (missing/invalid access credentials)
400 Invalid parameters or the request cannot be parsed
404 The requested path does not exist
405 Request method not supported
429 Too many requests; rate limit triggered
500 Internal system error

Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc