3

i want to create a file on my github account using github api through postman.

github api to create a file on github account:

PUT /repos/:owner/:repo/contents/:path 

can anyone tel me how to use this api in postman.

i have my public github account : https://github.com/ritzygithub/myfirstRepo

and in postman header i set

Authorization type to OAuth 2
Authorization : token <token>
PUT request with url: https://api.github.com/repos/ritzygithub/myfirstRepo/

enter image description here

Can you please help me out in this

Ritz Arlekar
  • 375
  • 1
  • 4
  • 20

1 Answers1

4

i just figured it out.. posting my answer here so that if anyone is facing same issue then this can help them.

In postman, set as PUT request with below URL

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

Add Body:

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

Header: Content-Type : application/json Authorization : token

Refer below Screenshot: enter image description here

Hope this helps. Thanks

Ritz Arlekar
  • 375
  • 1
  • 4
  • 20
  • 1
    Just to add that GitHub has deprecated the credentials based authentication and now you will need to generate a token, by going into your account and accessing the developer settings. – Mirza Sisic Mar 31 '21 at 14:25