How to create a github.com repository over HTTP API? - github

According to the general instruction to the github.com API and the explanation of the create command
curl -u "krichter722" https://api.github.com # works (returns JSON response)
curl -d '{"name":"test"}' https://api.github.com/user/repos/
should work and create a repository, but the second command fails with
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
I found Using `curl` to create a repo on GitHub.com with two-factor authentication which resolves an issue caused by missing parts in the request for two-factor authentication.
Other questions, like "Bad Credentials" when attempting to create a GitHub repo through the CLI using curl, indicate that the URL is correct (the creation fails due to bad credentials according to error message in this case).

You can do it as follows:-
curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'
You can find personal access token in Github Settings -> Application, replace username with your username and repo_name with repository name.
Note:- You might need to create personal access token if you haven't used it earlier.

Related

Github site admin curl not working for active users

curl -L -u DEV:$DEVTOKEN https://github.company-name.net/api/v3/stafftools/reports/active_users.csv
{
"message": "Not Found",
"documentation_url": "https://docs.github.com/enterprise/3.6/rest"
}
I am trying to curl by following directions here
https://docs.github.com/en/github-ae#latest/admin/configuration/configuring-your-enterprise/site-admin-dashboard
Why am I getting not found message error?
The "Reports" instruction does not include api/v3:
The site admin dashboard offers a Reports section as an alternative, making it easy for you to download CSV reports with most of the information that you are likely to need for users, organizations, and repositories.
curl -L -u USERNAME:TOKEN http(s)://HOSTNAME/stafftools/reports/all_users.csv

Issue of Authentication using GitHub API

I am trying to authenticate a user by GitHub API.
I've tried on two methods, Authentication via username and password and via personal access token(PAT) like this;
curl -u devmania1223 https://api.github.com/user /*via username and password*/
curl -u ghp_I60uniHdf6UKDCkyde1InP7kwRwsw2fD0wx https://api.github.com/user /*via personal access token*/
Inputted username and password, PAT correctly, but the response is not right.
{
"message": "Requires authentication",
"documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user"
}
So, What's wrong with curl command?
Try and use the token as password:
curl -i -u your_username:$token https://api.github.com/users/octocat
Don't forget the other option: gh (the GitHub cli/cli), using gh auth login
# authenticate against github.com by reading the token from a file
$ gh auth login --with-token < mytoken.txt
Let's say that your personal access token is 55a6f290558d11ecbeaf787b8ab956b4. Now, make a request using the GitHub API, put the token into the "Authorization" header:
/usr/bin/curl -H "Authorization: Bearer 55a6f290558d11ecbeaf787b8ab956b4" https://api.github.com/user
Why? Well, the type of token that GitHub gives to you is called "OAuth 2.0" token, and you just have to use it this way.

Registration in the git hub, git and the repository problem

I want to make a repository in GitHub for the first time and now it gives me this error
Username for 'https://github.com': ******`enter username here`
Password for 'https://m.erfanpld#github.com': `enter password here`
remote: Permission to MErfanPld/web.git denied to MErfanPld.
fatal: unable to access 'https://github.com/MErfanPld/web.git/': The requested URL returned error: 403
Thank you for your help
There are two ways you can access Github repositories when they are private.
HTTPS
SSH
I recommend the second method, You must create an ssh key using the command below
ssh-keygen
Now You can print Your ssh public key using the command bellow in Linux
cat ~/.ssh/id_rsa.pub
Use this link as a hint to manage your ssh keys.
Finally, you need to add your public ssh key into GitHub, Github explains this here with a picture guide. Now through ssh public key and without the need to log in with a username and password every single time, You can access your private repositories in a secure way.
Best regards

403 Forbidden while accessing github repo

I have generated an ssh key using the following
ssh-keygen -t rsa -C "your_email#example.com"
I have also added the ssh key to my github settings.
However, when I try and clone, I get this error message
Initialized empty Git repository in /home/somepath/.git/
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/somelink.git/info/refs
fatal: HTTP request failed
The same works from another laptop though
you can't authenticate to github with ssh keys using https urls. You need to use ssh: url (docs)

TeamCity with Github

I downloaded TeamCity 5 and I can see the option for Git under "Edit VCS Root". I have supplied the Clone Url, Branch
Authentication Method: Default Private Key
But when I test the connection I get the following error:
The connection test failed: com.jcraft.jsch.JSchException: UnknownHostKey: github.com. RSA key fingerprint i
Any ideas?
Below that there is a line that says:
Known Hosts Database:
Check the box next to that that says:
Do not check
You can try to connect over HTTP using authentication method "Password" with credentials you use at login page (email/password) instead of specifying SSH key.