You were close:) Lets assume, that

1) your login: YourUsername

2) your access token: 123a321

3) repository to be updated: YourRepo

4) file to be created: file.txt

5) folder that will contains new file: f1/f2

According to those assumptions your request should be following:

type : PUT

url : https://api.github.com/repos/YourUsername/YourRepo/contents/f1/f2/file.txt

headers :

{
 "Content-Type" : "application/vnd.github.v3+json",
 "Authorization" : "token 123a321"
}

body :

{
  "message": "my commit message",
  "committer": {
    "name": "My name",
    "email": "my email"
  },
  "content": "base64encoded"
}


UPD If you write in java, you can use GitHubFileAPI library, that I recently pushed to the maven central repository.

Answer from Wsl_F on Stack Overflow
🌐
GitHub
docs.github.com › rest › guides › getting-started-with-the-rest-api
Getting started with the REST API - GitHub Docs
The most common media types supported by the GitHub REST API are application/vnd.github+json and application/json. There are custom media types that you can use with some endpoints. For example, the REST API to manage commits and pull requests support the media types diff, patch, and sha.
🌐
GitHub
docs.github.com › en › rest › quickstart
Quickstart for GitHub REST API - GitHub Docs
For more information, see the GitHub CLI api documentation. This example makes a request to the "Get Octocat" endpoint, which uses the method GET and the path /octocat. For the full reference documentation for this endpoint, see REST API endpoints for meta data.
People also ask

Is the GitHub API free?
Yes, the GitHub API is free with rate limits, though higher usage levels may require authentication and paid plans for extended access.
🌐
hevodata.com
hevodata.com › home › learn › data strategy
Getting Started on How to Use Github REST API
How can I use the GitHub API?
You can use the GitHub API by sending HTTP requests to its endpoints (e.g., using curl or libraries like requests in Python) to interact with repositories, issues, users, etc.
🌐
hevodata.com
hevodata.com › home › learn › data strategy
Getting Started on How to Use Github REST API
How do I get users from GitHub API?
To get users from the GitHub API, send a GET request to the /users endpoint (e.g., https://api.github.com/users), or for specific users, use /users/{username}.
🌐
hevodata.com
hevodata.com › home › learn › data strategy
Getting Started on How to Use Github REST API
🌐
GitHub
docs.github.com › en › rest
GitHub REST API documentation - GitHub Docs
Follow these best practices when using GitHub's API. ... Use the REST API to get billing usage information.
Top answer
1 of 2
9

You were close:) Lets assume, that

1) your login: YourUsername

2) your access token: 123a321

3) repository to be updated: YourRepo

4) file to be created: file.txt

5) folder that will contains new file: f1/f2

According to those assumptions your request should be following:

type : PUT

url : https://api.github.com/repos/YourUsername/YourRepo/contents/f1/f2/file.txt

headers :

{
 "Content-Type" : "application/vnd.github.v3+json",
 "Authorization" : "token 123a321"
}

body :

{
  "message": "my commit message",
  "committer": {
    "name": "My name",
    "email": "my email"
  },
  "content": "base64encoded"
}


UPD If you write in java, you can use GitHubFileAPI library, that I recently pushed to the maven central repository.

2 of 2
0

Solution: In order to perform action on github api you can use curl according to Github doc:

  1. first make sure you have specific privileges and authentication token generated to your account in order to interact with Github api:

profile Settings -> Developer Settings -> Personal access tokens -> Generate new token

  1. the command should be in http PUT method on path /repos/:owner/:repo/contents/:path
  2. The required params for editing or adding new files (according to api) message (String), Content (String) and sha(String), additional params are branch(String) commiter(String) and author(String)

Lets perform some curl message in order to perform your action, the simple formula for this case would be:

curl --user <userName>:<token>
--data '{"key":"value"}'
--header <HeaderType>
--request <HTTPMethod>
<fullURL>

for demonstration lets fill some details:

 curl --user johnDoe:abc123!@#
 --data '{"message":"my message","content":"my content","sha":"abcjfhtenf736gd843ji43903"}'
 --header Content-Type:application/json
 --request PUT
https://api.github.com/repos/MyOrganization/MyCoolApp/contents/app/models
  1. Verify on Github the content has been inserted correctly to your branch
🌐
GeeksforGeeks
geeksforgeeks.org › git › getting-started-with-github-rest-api
Getting Started With GitHub REST API - GeeksforGeeks
July 23, 2025 - Here’s an example using curl to fetch your GitHub user details: curl -H "Authorization: token YOUR_PERSONAL_ACCESS_TOKEN" https://api.github.com/user · Replace YOUR_PERSONAL_ACCESS_TOKEN with your actual token.
🌐
Hevo
hevodata.com › home › learn › data strategy
Getting Started on How to Use Github REST API
January 9, 2026 - GitHub REST APIs allow users to communicate with GitHub and extract the desired information effectively by using an authenticated access token. With GitHub REST APIs, you can easily create and manage repositories, issues, branches, and more, with only a few lines of code.
🌐
Software Testing Help
softwaretestinghelp.com › home › github › github rest api tutorial – rest api support in github
GitHub REST API Tutorial - REST API Support In GitHub
April 1, 2025 - This GitHub Tutorial will explain how to use REST API for various actions to GET, PUT, POST, PATCH, DELETE data using the CURL Command.
Find elsewhere
🌐
GitHub
github.com › topics › rest-api-example
rest-api-example · GitHub Topics · GitHub
It is sbt sample project for quick start with writing Rest api using Akka Http. learning scala akka akka-http sbt getting-started scalatest learning-by-examples sample-project akka-http-testkit rest-api-example
🌐
GitHub
docs.github.com › en › rest › repos
REST API endpoints for repositories - GitHub Docs
Use the REST API to create, manage and control the workflow of public and private GitHub repositories.
🌐
Code Snippet
codesnippet.io › github-api-tutorial
How To Use the GitHub API - Build a Simple Web App - Code Snippet
November 21, 2022 - Click here for a comprehensive list of available GitHub API endpoints. For today's example will make use of the GET /users/<username>/repos endpoint which will allow us to list all public repositories for the specified <username> parameter.
🌐
GitHub
docs.github.com › en › rest › about-the-rest-api › about-the-rest-api
About the REST API - GitHub Docs
... You can use GitHub's API to build scripts and applications that automate processes, integrate with GitHub, and extend GitHub. For example, you could use the API to triage issues, build an analytics dashboard, or manage releases.
🌐
GitHub
github.com › github › docs › blob › main › content › rest › using-the-rest-api › getting-started-with-the-rest-api.md
docs/content/rest/using-the-rest-api/getting-started-with-the-rest-api.md at main · github/docs
... Examples in this article send requests to {% data variables.product.rest_url %}. If you access {% data variables.product.github %} at a different domain, such as {% data variables.enterprise.data_residency_example_domain %}, the endpoint ...
Author: github
🌐
GitHub
docs.github.com › en › rest › authentication › authenticating-to-the-rest-api
Authenticating to the REST API - GitHub Docs
For example, in the following request, replace YOUR-TOKEN with a reference to your token: curl --request GET \ --url "https://api.github.com/octocat" \ --header "Authorization: Bearer YOUR-TOKEN" \ --header "X-GitHub-Api-Version: 2026-03-10" ...
🌐
OpenClassrooms
openclassrooms.com › en › courses › 7646551-build-your-web-projects-with-rest-apis › 7739275-learn-how-to-use-the-github-api
Learn How to Use the GitHub API - OpenClassrooms
🙌 Launch Postman! Select POST from the drop-down menu, then type in the endpoint for creating a new repo using the GitHub API: https://api.github.com/user/repos, and then hit Send.
🌐
GeeksforGeeks
geeksforgeeks.org › git › github-rest-api
GitHub REST API - GeeksforGeeks
January 19, 2026 - Here are some of the most commonly used endpoints: List repositories: GET /user/repos or GET /orgs/:org/repos ... You can explore all available endpoints in the GitHub REST API ...
🌐
GitHub
docs.github.com › en › rest › repos › contents
REST API endpoints for repository contents - GitHub Docs
For example, instead of an array of objects for a directory, the response will be an object with an entries attribute containing the array of objects. If the content is a directory: The response will be an array of objects, one object for each ...
🌐
GitHub
docs.github.com › en › rest › users › users
REST API endpoints for users - GitHub Docs
March 10, 2026 - { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions"
🌐
Medium
medium.com › @ahmetbostanciklioglu › rest-api-endpoint-for-github-api-338dbec08106
Rest API endpoint for Github API. From scratch we will look at how to… | by Ahmet Bostanciklioglu | Medium
May 1, 2025 - Rest API endpoint for Github API From scratch we will look at how to read a GitHub API for repository. What is the REST API? REST (representational state transfer) is bridge between client …