Please provide working code that creates a Github repository using the API.
I have tried different versions of the following:
curl 'https://api.github.com/users/repos?client_id= myusername&client_secret=abcdefghijklmnopqrstuvwxyz1234567890abcd'
curl -u 'myusername' https://api.github.com/users/repos -d '{"name":"my-new-repo"}'
But I always get the following error:
"{
\"message\": \"Bad credentials\",
\"documentation_url\": \"https://developer.github.com/v3\"
}"
The following works:
(without variables) curl -H "Authorization: token abcdefghijklmnopqrstuvwxyz1234567890abcd" --data '{"name":"name-foo"}' https://api.github.com/user/repos
(with variables)
NAME='name-foo' TOK='abcdefghijklmnopqrstuvwxyz1234567890abcd' BASE='https://api.github.com/' EXT='user/repos' URL=$BASE$EXT curl -H "Authorization: token $TOK" --data "{\\"name\\":\\"$NAME\\"}" $URL
One can use personal access tokens instead of OAuth .
The YOUR_TOKEN
value in the "Authorization: token YOUR_TOKEN"
section of the curl
command can be obtained as follows.
For more details, click here and here .
This is how I did it in an organization, creating an internal
repository:
curl -X POST 'https://api.github.com/orgs/myorg/repos' \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Authorization: Bearer xxx' \
-d '{"name":"myrepo","visibility":"internal"}'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.